These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Ununderstanding NULL value on collection
PostPosted: Fri Aug 21, 2009 5:51 am 
Newbie

Joined: Wed Feb 04, 2009 5:26 am
Posts: 5
Hi,

My last issue is the following :
@Table(name = "A")
@MappedSuperclass
public Abstract class A {
...
}

@Entity
@MappedSuperclass
@Table(name = "B")
@AccessType("field")
public class B extends A {

@Id
@GeneratedValue
protected long hId;

@OneToMany(cascade = javax.persistence.CascadeType.ALL)
@JoinTable(name = "B_ARGS")
protected Map<String, BigString> args = new HashMap<String, BigString>();

...
}

@Entity
@Table(name = "C")
@AccessType("field")
public class C extends B {
...
}

when storing an instance of B, I get this exception :
org.hibernate.exception.ConstraintViolationException: could not insert collection: [B.args#360448]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:94)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.persister.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:1205)
at org.hibernate.action.CollectionRecreateAction.execute(CollectionRecreateAction.java:58)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:171)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:365)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
Caused by: java.sql.SQLException: Column 'B_ARGS_HID' cannot accept a NULL value.
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(Unknown Source)
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:46)
at org.hibernate.persister.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:1168)
... 27 more
Caused by: ERROR 23502: Column 'B_ARGS_HID' cannot accept a NULL value.
at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
at org.apache.derby.impl.sql.execute.NormalizeResultSet.normalizeColumn(Unknown Source)
at org.apache.derby.impl.sql.execute.NormalizeResultSet.normalizeRow(Unknown Source)
at org.apache.derby.impl.sql.execute.NormalizeResultSet.getNextRowCore(Unknown Source)
at org.apache.derby.impl.sql.execute.DMLWriteResultSet.getNextRowCore(Unknown Source)
at org.apache.derby.impl.sql.execute.InsertResultSet.open(Unknown Source)
at org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(Unknown Source)
at org.apache.derby.impl.sql.GenericPreparedStatement.execute(Unknown Source)

It's the same with an instance of C.
As shown in the stack trace, I'm using derby.
Printing hibernate request, the exception occurs when doing the following request :
insert into B_ARGS (B_ARGS_hId, mapkey, args_ID) values (?, ?, ?)

where B_ARGS_hId seems to be null. I don't understand why ? I tried with other inheritance strategy without success.


in Fact, the created table look like : B_ARGS_hId | C_ARGS_hId | ARGS_ID | MAPKEY
We can see that both FK 'B_ARGS_hId' and 'C_ARGS_hId' have been created and mustnot be null.
So when storing an entry in this table and according to the request above, B_ARGS_hId OR C_ARGS_hId will be null at any time. How should I proceed ?

Thx for help, JL.


Top
 Profile  
 
 Post subject: Re: Ununderstanding NULL value on collection
PostPosted: Sat Aug 22, 2009 3:18 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
When you are initializing your collection, are you setting both sides? So you have a

Code:
b.setCollectionA(listOfAs);


and

Code:
a.setCollectionB(listOfBs);

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.