[Hibernate Mysql 5 EJB3 JBoss] remove() foreign key constraint fails
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I'm trying to delete an object which has a OneToMany Relationship
Father
Children
EJB3
Error stack trace
16:06:40,671 ERROR [JDBCExceptionReporter] Cannot delete or update a parent row: a foreign key constraint fails (`test/USR_ADDRESS`, CONSTRAINT `FK949D64094F8AB6BC` FOREIGN KEY (`user_fk_id`) REFERENCES `USR` (`id`))
16:06:40,672 ERROR [AbstractFlushingEventListener] Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
Caused by: java.sql.BatchUpdateException: Cannot delete or update a parent row: a foreign key constraint fails (`test/USR_ADDRESS`, CONSTRAINT `FK949D64094F8AB6BC` FOREIGN KEY (`user_fk_id`) REFERENCES `USR` (`id`))
at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1213)
With EJB3, the transaction is not managed by the container?
What am I missing here?
Thanks in advance
trying to decode a woman mind....
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
2.2.5.3.2.1. Bidirectional
To map a bidirectional one to many, with the one-to-many side as the owning side, you have to remove the mappedBy element and set the many to one @JoinColumn as insertable and updatable to false. This solution is obviously not optimized and will produce some additional UPDATE statements.
@Entity
public class Troop {
@OneToMany
@JoinColumn(name="troop_fk") //we need to duplicate the physical information
public Set<Soldier> getSoldiers() {
...
}
@Entity
public class Soldier {
@ManyToOne
@JoinColumn(name="troop_fk", insertable=false, updatable=false)
public Troop getTroop() {
...
}
Try it out and see if it works.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Unfortunatly it does not work.
I'm just wondering if it's a bug or my mistake.

trying to decode a woman mind....
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
trying to decode a woman mind....
| On top of spaghetti all covered in cheese, there was this tiny ad: The new gardening playing cards kickstarter is now live! https://www.kickstarter.com/projects/paulwheaton/garden-cards |











