Daniel Lyons
Daniel Lyons

Reputation: 22803

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 using 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!

Upvotes: 2

Views: 937

Answers (1)

DataNucleus
DataNucleus

Reputation: 15577

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

Upvotes: 1

Related Questions