EDIT So, I switched from Glassfish to Wildfly and was using EclipseLink 2.5. This code stopped working when I switched, with the below problems. The entity manager was created with resource local transactions for some reason.
I tried lots of things, but when I switched to Hibernate EM everything worked just fine. END EDIT
I'm using Wildfly 10 and Eclipselink JPA to have a simple Stateless EJB save a record to a database. The methods are here:
This bean is marked @Stateless
@POST
@Override
@Consumes({"application/xml", "application/json"})
public void create(Actor entity) {
L.info("Creating {}", entity);
super.create(entity);
L.info("Created");
}
Here is the abstract parent's method:
public void create(T entity) {
//getEntityManager().getTransaction().begin();
getEntityManager().persist(entity);
//getEntityManager().flush();
//getEntityManager().getTransaction().commit();
}
If I uncomment the transactional code, it works.
If I add the transaction annotation, it does not work.
Like this, it does not work.
Why? I though EJBs got container managed transactions and that this should be auto-committed. Here is my persistence unit definition:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="net.mikeski_auth_war_0.1.0-SNAPSHOTPU" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>java:jboss/datasources/PostgresqlDS</jta-data-source>
<class>entities.Actor</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="eclipselink.weaving" value="false"/>
<property name="eclipselink.weaving.fetchgroups" value="false"/>
<property name="javax.persistence.schema-generation.database.action" value="create"/>
</properties>
</persistence-unit>
</persistence>
I know my entity is good because if I add some to the DB the find methods work, and if I get the transactions right the inserts work. What am I missing?