users@glassfish.java.net

Glassfish creates a table that it cannot use.

From: <glassfish_at_javadesktop.org>
Date: Sun, 13 Jan 2008 23:28:14 PST

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 {
&nbsp;&nbsp; @Id
&nbsp;&nbsp; @SequenceGenerator(name="CSeq")
&nbsp;&nbsp; @GeneratedValue(strategy = GenerationType.SEQUENCE, generator"CSeq")
&nbsp;&nbsp; private int id;
&nbsp;&nbsp; @OneToMany
&nbsp;&nbsp; Collection&lt;A&gt; foo = new Vector&lt;A&gt;();
&nbsp;&nbsp; @OneToMany
&nbsp;&nbsp; Collection&lt;B&gt; bar = new Vector&lt;B&gt;();
}

This generates tables for A, B and C as well as a joining table C_A with the fields show below:
C_A
&nbsp;&nbsp; C_ID (not null)
&nbsp;&nbsp; FOO_ID (not null)
&nbsp;&nbsp; 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
&nbsp;&nbsp; C_ID (not null)
&nbsp;&nbsp; FOO_ID (not null)

C_B
&nbsp;&nbsp; C_ID (not null)
&nbsp;&nbsp; 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