开发者

JDO with Java EE 6 (CDI and JTA?)

I apologize if this is an obvious question, but I'm going through the Java EE 6 tutorial while reading a couple books and it's getting hard to correlate all of the information.

I'm doing a little comparison between JDO and JPA. I understand that with JPA and an application server, I can quite easily say something like:

@Stateless
public class MyEJB {

  @PersistenceContext
  private EntityManager em;

  // methods that use the JPA entity manager...
}

Then, within my own methods, I can use em to get at a JPA EntityManager. Whatever methods I write will (by default) automatically create or join up with an existing transaction.

I'd like to have this much fun with JDO. I suspect the right answer is to use CDI. I'm not sure what that would look like though, perhaps this?

@Stateless
public class MyEJB {

  @Resource
  private PersistenceManager em;

  // methods that use the JDO persistence manager...
}

But this guesswork leaves me with more questions than answers.

  1. How do I tell Glassfish or whatever my Java EE 6 application server turns out to be, how to make the PersistenceManagerFactory and how to use it to generate PersistenceManagers for me?
  2. Do I have to do anything special to achieve JTA? I'd like to be usin开发者_运维问答g container managed transactions if possible.
  3. Can I set this up to use JNDI to find my JDBC connection?
  4. Are there magical files that need to exist to trigger the behavior I want? (I'm looking at you, empty persistence.xml)

Apart from imposing a dependency on JDO and probably DataNucleus directly I'd rather keep this as Java EE 6 as possible, without involving Spring or other third party libraries, but I'd take a third party library over nothing.

Thanks!


http://www.datanucleus.org/products/accessplatform_3_0/jdo/j2ee.html covers many aspects of Java EE, and gives examples for several Java EE servers including JBoss 7 (the latest spec). It is a contributory effort since nobody uses all such servers; if you have details to add then post them on the DataNucleus forum and they can be included

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜