[jboss-user] [EJB 3.0] - Bug in @OneToMany() table creation.
webmarck
do-not-reply at jboss.com
Thu Nov 23 04:46:08 EST 2006
I haven?t created a bug rapport yet ? wanted to have your opinion first.
I have an entity bean that has 3 OneToMany relationships with another enity bean.
public class Information {
| ?
| @OneToMany()
| public Collection<InformationText> getContexts() {
| return context;
| }
| @OneToMany
| public Collection<InformationText> getHeadlines() {
| return headline;
| }
| @OneToMany
| public Collection<InformationText> getLinkTexts() {
| return linkText;
| }
| ?
| }
|
In persistence.xml I have hibernate create tables and this is the SQL it uses (PostgreSQL)
CREATE TABLE information_informationtext
| (
| information_id int8 NOT NULL,
| linktexts_id int8 NOT NULL,
| headlines_id int8 NOT NULL,
| contexts_id int8 NOT NULL,
| CONSTRAINT fk26384b2658965112 FOREIGN KEY (headlines_id)
| REFERENCES informationtext (id) MATCH SIMPLE
| ON UPDATE NO ACTION ON DELETE NO ACTION,
| CONSTRAINT fk26384b26b2a6936d FOREIGN KEY (contexts_id)
| REFERENCES informationtext (id) MATCH SIMPLE
| ON UPDATE NO ACTION ON DELETE NO ACTION,
| CONSTRAINT fk26384b26bdddc9e5 FOREIGN KEY (linktexts_id)
| REFERENCES informationtext (id) MATCH SIMPLE
| ON UPDATE NO ACTION ON DELETE NO ACTION,
| CONSTRAINT fk26384b26c9808d98 FOREIGN KEY (information_id)
| REFERENCES information (id) MATCH SIMPLE
| ON UPDATE NO ACTION ON DELETE NO ACTION,
| CONSTRAINT information_informationtext_contexts_id_key UNIQUE (contexts_id),
| CONSTRAINT information_informationtext_headlines_id_key UNIQUE (headlines_id),
| CONSTRAINT information_informationtext_linktexts_id_key UNIQUE (linktexts_id)
| )
|
The problem is the NOT NULL constraints on linktexts_id, headlines_id and contexts_id. When I try to persist anything on the bean I get the following exception.
| 10:29:51,703 ERROR [JDBCExceptionReporter] Batch entry 0 insert into Information_InformationText (Information_id, contexts_id) values (933, 930) was aborted. Call getNextException to see the cause.
| 10:29:51,703 WARN [JDBCExceptionReporter] SQL Error: 0, SQLState: 23502
| 10:29:51,703 ERROR [JDBCExceptionReporter] ERROR: null value in column "linktexts_id" violates not-null constraint
| 10:29:51,703 ERROR [AbstractFlushingEventListener] Could not synchronize database state with session
| org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
| at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
|
If I create the table myself without the NOT NULL constraint on linktexts_id, headlines_id and contexts_id then everything works.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3988096#3988096
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3988096
More information about the jboss-user
mailing list