Reputation: 387
Caused by: javax.transaction.RollbackException: Transaction marked for rollback.
at com.sun.enterprise.transaction.JavaEETransactionImpl.commit(JavaEETransactionImpl.java:473)
at com.sun.enterprise.transaction.JavaEETransactionManagerSimplified.commit(JavaEETransactionManagerSimplified.java:852)
at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:5114)
... 63 more
Caused by: java.lang.IllegalStateException: During synchronization a new object was found through a relationship that was not marked cascade PERSIST: com.model.Product[ id=1 ].
at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.discoverUnregisteredNewObjects(RepeatableWriteUnitOfWork.java:302)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.calculateChanges(UnitOfWorkImpl.java:695)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitToDatabaseWithChangeSet(UnitOfWorkImpl.java:1482)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.issueSQLbeforeCompletion(UnitOfWorkImpl.java:3135)
at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.issueSQLbeforeCompletion(RepeatableWriteUnitOfWork.java:344)
at org.eclipse.persistence.transaction.AbstractSynchronizationListener.beforeCompletion(AbstractSynchronizationListener.java:157)
at org.eclipse.persistence.transaction.JTASynchronizationListener.beforeCompletion(JTASynchronizationListener.java:68)
at com.sun.enterprise.transaction.JavaEETransactionImpl.commit(JavaEETransactionImpl.java:435)
... 65 more
i got this rollbackexception during inserting an entity to db with persist()
method.....what is the reason behind this exception?
Upvotes: 1
Views: 6781
Reputation: 6158
Before inserting check you hbm
files, may there some cascading problem( set cascade=all
).
Upvotes: 1
Reputation: 9928
Check that you have set all bi-directional relationships (between your com.model.Product
entity and other entities related to it) correctly.
For example, if there was a Many-1 relationship from Product
to Manufacturer
you would have something like:
Product product = new Product();
product.setId(1);
Manufacturer manufacturer = new Manufacturer ();
manufacturer.setId(123);
product.setManufacturer(manufacturer); // set Many-1 side of relationship
Set<Product> products = new HashSet<Product>();
products.add(product);
manufacturer.setProducts(products); // set 1-Many side of relationship
Upvotes: 3