users@glassfish.java.net

Re: diferent behaviour between GeneratedType.AUTO and GeneratedType.SEQUENC

From: <glassfish_at_javadesktop.org>
Date: Tue, 19 Feb 2008 12:56:23 PST

Dear Marina,

  Thanks, I did it but the problem remains.

  The very question is:

  (1) Using GeneratedType.AUTO :

    A a = new A(); // a.id is null ==> ok
    ...
    em.persist(a); // after this command a.id is not null ==> ok

  
   (2) Using GeneratedType.SEQUENCE :

    A a = new A(); // a.id is null ==> ok
    ...
    em.persist(a); // after this command a.id still is null ==> is this ok?

   In case (1) I can set an id to b:
    ...
    B b = new B();
    a.setB(b);
    b.setId(a.getId()); // this is ok because a.id is not null

In case (2) the same code doesn't run because a.id is still null:

Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))): oracle.toplink.essentials.exceptions.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: ERROR: null value in column "id" violates not-null constraint
Error Code: 0
Call: INSERT INTO B (ID) VALUES (?)
        bind => [null]
Query: InsertObjectQuery(ts.lgica.B[id=null])


    Thanks,

   Leandro
[Message sent by forum member 'leandro_komosinski' (leandro_komosinski)]

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