users@glassfish.java.net

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

From: <glassfish_at_javadesktop.org>
Date: Fri, 15 Feb 2008 11:51:16 PST

Let me explain the problem again:

Classes A and B have a one-to-one required association. So I can't persist an A object without having a B object.

A's PK is generated by a database sequence (Postgres in my case) (GeneratedType.SEQUENCE) and B's PK is application's responsability (no GeneratedValue annotation).

So, the following method doesn't run because b object doesn't have id:

A a = new A();
B b = new B();

public void test() {
  em.persist(a);
  a.setB(b); // one-to-one required association
  b.setId(a.getId());
}

If I change A to GeneratedValue.AUTO then the method runs ok.

Is this ok?

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

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