File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA 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
Author

Exception when adding a child in one-to-many

Ross Hendry
Greenhorn

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
Greenhorn

Joined: May 03, 2007
Posts: 8
Solved by changing the relationship to a @ManyToMany like it should be. Doh!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception when adding a child in one-to-many