my dog learned polymorphism*
The moose likes Object Relational Mapping and the fly likes Exception when adding a child in one-to-many Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Exception when adding a child in one-to-many" Watch "Exception when adding a child in one-to-many" New topic

Exception when adding a child in one-to-many

Ross Hendry

Joined: May 03, 2007
Posts: 8
Quick situation overview - I've got an entity called a PartHolderNode which has a collection of entities called RepositoryItems. I'm trying to add an existing RepositoryItem into an existing PartHolderNode's collection. Instead of a slightly bigger collection, I get an exception stating "Unable to commit". The mapping seems to be correct based on the fact that if I add a new (not persisted) RepositoryItem to a collection and call merge it persists to the database as expected.

Detail -

Inside a stateless controller bean for PartHolderNodes I had the following method -

manager.persist() has also been tried as manager.merge().

Unfortunately, this results in the following -

The JBoss logs show that it has executed an update to the join table between the two entities, but when it attempts to "close PreparedStatement" it throws the JDBCException stating "Could not execute JDBC batch update".

Surely adding an element to a collection and saving the change to the db should be straightforward? What have I missed this time?!

The relationship between PHN and RIs is mapped as follows -

and the addFile(foo) method in the controller bean just consists of files.add(foo.)

If you need any more detail just let me know.
[ May 17, 2007: Message edited by: Ross Hendry ]
Ross Hendry

Joined: May 03, 2007
Posts: 8
Solved by changing the relationship to a @ManyToMany like it should be. Doh!
wood burning stoves
subject: Exception when adding a child in one-to-many
Similar Threads
Problem in persisting Entity with Composite Key
Regarding Entirty relationships...
onetoone unidirectional relationship problem
jboss4.0.5.GA ejb3 error while persisiting one to one entity
Persisting second identical object causes ConstraintViolationException?