I am using NetBeans 6.0, Glassfish V2, Java 1.6. I have the following code (the class names have been changed to protect the innocent):
class A {
}
class B extends A {
}
class C {
@Id
@SequenceGenerator(name="CSeq")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator"CSeq")
private int id;
@OneToMany
Collection<A> foo = new Vector<A>();
@OneToMany
Collection<B> bar = new Vector<B>();
}
This generates tables for A, B and C as well as a joining table C_A with the fields show below:
C_A
C_ID (not null)
FOO_ID (not null)
BAR_ID (not null)
When I try to insert into foo, I get the error:
Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.0 (Build b58g-fcs (09/07/2007))): oracle.toplink.essentials.exceptions.DatabaseException
Internal Exception: java.sql.SQLIntegrityConstraintViolationException: Column 'BAR_ID' cannot accept a NULL value.
Error Code: -1
Call: INSERT INTO C_A(foo_ID, C_ID) VALUES (?, ?)
bind => [7, 4]
Query: DataModifyQuery()
at oracle.toplink.essentials.exceptions.DatabaseException.sqlException(DatabaseException.java:311)
[…]
Glassfish has apparently created a table that it cannot populate. I want to overcome this problem. I think that a good way to overcome this problem would be to have Glassfish create and use two joining tables like this:
C_A
C_ID (not null)
FOO_ID (not null)
C_B
C_ID (not null)
BAR_ID (not null)
How can I do this?
[Message sent by forum member 'dannycron' (dannycron)]
http://forums.java.net/jive/thread.jspa?messageID=253685