I trying understand how EJB JTA works. I have a simple Bean:
@Stateless
public class DictionariesCategoriesFacade extends AbstractFacade<DictionariesCategories> {
@PersistenceContext(unitName = "org.web_system-ejb_ejb_1.0-SNAPSHOTPU")
private EntityManager em;
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void save(DictionariesCategories dictionariesCategory, DictionariesCategories parentCategory, DictionariesCategoriesNames dictionariesCategoriesNames) {
// here no transaction
em.merge(dictionariesCategory); // this works
em.persist(dictionariesCategoriesNames); // here i get constraint from database beacuse dictionariesCategoriesNames dont have set a name value. This value is required (NOT NULL) i do that deliberately.
}
}
After call this method in my database is persisted first command
em.merge(dictionariesCategory);
but second is failed. (here i get javax.validation.ConstraintViolationException)
em.persist(dictionariesCategoriesNames); // throws javax.validation.ConstraintViolationException
I expect that, the PersistenContext will do rollback automatic and first command dont be persisted in database. Why my transaction here dosent work? Can someone help with this issue i will greatfuly for help
here my persisten.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="org.web_system-ejb_ejb_1.0-SNAPSHOTPU" transaction-type="JTA">
<jta-data-source>java:/jboss/datasources/postgresql</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties/>
</persistence-unit>
</persistence>