Testing jpa entity classes - error Transaction is required

前端 未结 1 419
天涯浪人
天涯浪人 2021-01-16 08:20

Based on an archetype i created a java ee app. There is an included arquillian test that runs fine. it just calls a method on a @Stateless bean that persists an pre-made ent

相关标签:
1条回答
  • 2021-01-16 08:58

    In order to have transaction support in Arquillian tests you will need to bring in extension which enables this feature. In your case jta dependency should do the job.

    <dependency>
      <groupId>org.jboss.arquillian.extension</groupId>
      <artifactId>arquillian-transaction-jta</artifactId>
      <scope>test</scope>
    </dependency>

    In addition, if you are using JBoss, you will need to provide its JNDI for UserTranscation, so put following section in your arquillian.xml:

    <?xml version="1.0" ?>
    <arquillian xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://jboss.org/schema/arquillian" xsi:schemaLocation="http://jboss.org/schema/arquillian
        http://jboss.org/schema/arquillian/arquillian_1_0.xsd">     
    
      <extension qualifier="transaction">
        <property name="manager">java:jboss/UserTransaction</property>
      </extension>
    
    </arquillian>
    

    This way you can use @Transactional which comes from this extension's API.

    0 讨论(0)
提交回复
热议问题