Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] Inserting into a Parent and Child table using IDENTITY

Hi,

I have a parent table with an autogenerated primary key and a one to one table which is a child thus contains the parent's primary key.

The partent table entity class has the @GeneratedValue(strategy = GenerationType.IDENTITY)

When I persist the parent using the em.persist(parent) method, it tries to insert the child as well which is correct behavior.  However, it doesn't have the ID of the parent yet so tries to insert a NULL into the child table which is wrong.  I'm sure this is a fairly common problem, is there a workaround to this?  I know I could get this to work using a different ID generation strategy but is it possible to do this using IDENTITY?

Any help is appreciated.

Thanks,
Zarar

Back to the top