[jboss-dev-forums] [JBoss AS7 Development] - javax.persistence.TransactionRequiredException

Marcus Schmidke do-not-reply at jboss.com
Tue Oct 11 04:42:30 EDT 2011


Marcus Schmidke [http://community.jboss.org/people/MSchmidke] created the discussion

"javax.persistence.TransactionRequiredException"

To view the discussion, visit: http://community.jboss.org/message/631054#631054

--------------------------------------------------------------
Hello 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 http://java.sun.com/xml/ns/persistence" xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation=" http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence  http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd 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.
--------------------------------------------------------------

Reply to this message by going to Community
[http://community.jboss.org/message/631054#631054]

Start a new discussion in JBoss AS7 Development at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2225]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-dev-forums/attachments/20111011/5b1dc98a/attachment.html 


More information about the jboss-dev-forums mailing list