2010/01/11

Experimenting with Datanucleus JPA

I have been using Hibernate for a very long time, and I'm more or less satisfied with it. When I saw that Google App Engine uses the JPA/JDO implementation of Datanucleus for high level persistence, I decided to create a sample JPA project with it.



My goal was to implement one single project, where the Hibernate and the Datanucleus JPA providers live between each other peacefully, so they can be easily compared using the same set of unit tests. Because Datanucleus uses bytecode enhancement I decided to use runtime enhancement to avoid the build-time modification of the generated class files.

I created a very simple test case using detached entities, because the correct handling of detached instances is a core requirement for many applications. Hibernate 3.3.2.GA worked as expected but Datanucleus 1.1.6 failed with a strange exception:

Caused by: org.datanucleus.exceptions.NucleusException: Object with id "102" in table CHILD has no version set on the object in memory and you want to delete it!! Please report this bug to the developers of DataNucleus with a way of reproducing it

I tried to get some help on the Datanucleus JPA forum where I was told that 1.1 is not maintained. 2.0 is current. The answer was very fast but a bit interesting because I posted my question on 2010.01.09., and 2.0 was released on the same day. Maybe if I had posted my question a day earlier, I would have got a more positive answer :) - just joking, I understand that the developers do not have time for everything. However the Datanucleus community seems to be smaller and less reponsive than of Hibernate.

I had a minor problem with copying the logs from the Eclipse console because some weird characters  made the copy operation to fail (see ID=Xid=????):



I followed the advice and switched to Hibernate 3.5.0-Beta-2 and Datanucleus-2.0.0-release. Hibernate worked again as expected, but with Datanucleus I got unexpected behaviour, it seemed that the detached instances were merged incorrectly (see my forum post and the unit test).

At this point my initial interest disappeared completely, so I returned to Hibernate and hibernate-pojo-bridge...



Resources:
  • Maven project (after checkout, the lauch configuration of the Datanucleus test should be edited, because it contains direct reference to the local maven repository)

2 comments:

  1. Setting the property "datanucleus.Optimistic" to "false" in persistence.xml would have been a workaround for the issue "Object with id "102" in table CHILD has no version set on the object in memory and you want to delete it!! Please report this bug to the developers of DataNucleus with a way of reproducing it". Best regards ;-)

    ReplyDelete
  2. Wonderful blog & good post.Its really helpful for me, awaiting for more new post. Keep Blogging!

    JAVA Training in Chennai

    ReplyDelete