javax.persistence.TransactionRequiredException
mschmidke Oct 11, 2011 4:42 AMHello all,
after years of developing with Seam 2.x, I now try to jump start into a new world (AS7, builtin CDI etc.), but until now, I am not very succesful.
I've written a very simple sample application, a few entities and one servlet. After lots of work, everything deploys fine, Hibernate generates tables, well.
Then I call the servlet from Webbrowser. The servlet does nothing else than injecting and calling a SLSB, which itself tries to create and persist an entity.
With Seam 2.x, I never worried about transactions - everything was fully automatic. In fact, I have absolutely no knowledge about EJB3 CMT, because Seam did everything for me.
But now the only thing I get this this weird TransactionRequiredException. Google does not know anything about it (sureley because it is an absolute beginner's error).
My servlet:
@WebServlet(urlPatterns = "/*")
public class VaadinAppServlet extends HttpServlet {
@Inject
Beispieldaten bd;
@Override
protected void service(HttpServletRequest arg0, HttpServletResponse arg1)
throws ServletException, IOException {
bd.run();
super.service(arg0, arg1);
}
}
The SLSB:
@Stateless
@TransactionManagement(TransactionManagementType.CONTAINER)
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class BeispieldatenImpl implements Beispieldaten {
@PersistenceContext
private EntityManager session;
public void run() {
TestEntity te=new TestEntity();
session.persist(te);
}
}
(as you can see, I added lots of useless annotations just to avoid any possible mistake)
And the interface:
@Local
public interface Beispieldaten {
void run();
}
persistence.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="KochbuchServer"
transaction-type="JTA">
<jta-data-source>java:jboss/datasources/KochbuchDS</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.default_batch_fetch_size" value="100" />
<property name="hibernate.hbm2ddl.auto" value="create" />
<property name="jboss.entity.manager.factory.jndi.name"
value="java:/EntityManagerFactories/KochbuchServer" />
</properties>
</persistence-unit>
</persistence>
All packaged in an EAR - servlet in WAR, other classes in EJB-module.
I'm sure my mistake is quite obvious, but I need help ...
Thank you!
Marcus.