users@glassfish.java.net

Question on JPA generating the wrong database commands

From: <glassfish_at_javadesktop.org>
Date: Tue, 28 Aug 2007 06:03:34 PDT

I have a set of entity classes that I'm using in a J2EE application (EAR). I am creating the database schema for these entity classes through an ant script which works fine. I also need to initialize a few of the entities once the database is created and because it was easier, I wrote a standalone persistence application to do so.

I'm using the JavaDB (Derby) as my persistence database.

I was getting a problem periodically when I would run this application in that it would through a database exception indicating that it was trying to insert a record that had a one to many relationship with another table and the a NULL value was not allowed. In the persistence application all of the relationships were created correctly and there should not be NULL value. Sometimes the application would work and sometimes it would not with no code changes and it had me baffled.

I finally figured out when the application would not work. If I run the standalone persistence application immediately after creating the database schema using my ant script, the application will fail with the above error. If I shutdown the database server process and restart it, then the application will run fine, again with no code changes to the application.

Note that Glassfish is not running in either case as I'm just creating my database schema and trying to initialize some of the entities.

So why would shutting down the database server process and restart it have such an effect?
[Message sent by forum member 'bbergquist' (bbergquist)]

http://forums.java.net/jive/thread.jspa?messageID=232901