[jboss-user] [JBoss Seam] - FK violation persist ignored with many-to-many parent & join

eellis do-not-reply at jboss.com
Sun Aug 26 15:57:06 EDT 2007


I've done a bit of research and had mulled over this for several days before changing my schema to not require a many-to-many join. The issue is very simple:

I am using Seam-2.0.0-Beta with Hibernate. 

The user registration form on the website that I'm building has a checkbox for "receive email alerts". The client has asked that email alerts be a feature type where a user may subscribe to different features using the many-to-many user_features join table.

Table: user
Table user_feature
Table: feature

I have a fairly good understanding of the wiring involved with joining EntityHome instances but am not able to submit the form and within the same "userProfileAction" both create a new user (using UserHome), persist that user, then use that UserHome.getInstance() to persist the UserFeature join entity. 

For some reason UserHome.persist() does not persist before attempting to persist the UserFeature. No matter what I try or how verbose I am about persisting and flushing, the transaction seems to wait until all Hibernate commands are complete.

I am not able to write the User record, obtain it's ID, then use that ID to obtain a real User record to be used in joining the UserFeature. Again, because hibernate will not persist the record to the database for me before attempting to write the join record. 

I am actually able to query (EJBQL) for the new User record after calling UserHome.persist() and it actually returns the correct ID and instance for that record. I still receive the FK violation though because Hibernate has not written that record to the DB.

Can anyone assist me in getting my join table record to persist? There are quite a few items to cover here so I will be as prompt as possible in responding with code snippets and more detailed information.

It is very possible that I have simply missed out on a proven technique for doing this. Please share the wealth if you've done this before.


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4078163#4078163

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4078163



More information about the jboss-user mailing list