开发者

not defined a non-jta-data-source in JPA

I have JPA mapping to HSQLDB and persistence.xml reads as below:

<persistence-unit name="HMC">
  <jta-data-source>java:hmc</jta-data-source>
  <class>org.hmc.jpa.models.BloodGroup</class>
  <class>org.hmc.jpa.models.ContactInfo</class>
  <properties>
    <property 
      name="hibernate.transaction.manager_lookup_class"
      value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
    <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" />
  </properties>
</persistence-unit>

But whenever application is deployed, it JBoss throws RuntimeException saying: Specification violation [EJB3 JPA 6.2.1.2] - You have not defin开发者_如何学Ced a non-jta-data-source for a RESOURCE_LOCAL enabled persistence context named: ABC

I also have datasource defined in JBoss. Is there anything that I am missing in the configuration?

Regards, Satya


  1. if the transaction type of the persistence unit is JTA, the jta-datasource element is used to declare the JNDI name of the JTA data source that will be used to obtain connections. This is the common case.
  2. if the transaction type of the persistence unit is resource-local, the non-jta-data-source should be used to declare the JNDI name of a non-JTA data source.


hat is happening is that JBoss automatically scans and validates files named persistence.xml, since you are using spring to manage your beans, I guess you are not using EJB3.

What needs to be understood is if you want JBoss to control JTA transactions for you and if you want to use JBoss Transaction Manager, or if you just want to do JPA transactions, without JTA transaction control.

If you want to just use the JPA transactions and skip JBoss TransactionManagener, you can just rename your persistence.xml file to spring-persistence.xml (or whatever you like), and in spring-context.xml file you can change your entityManagerFactory to this:

<!-- JPA primary EntityManagerFactory -->  
      <bean id="entityManagerFactory" lazy-init="true"  
          class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"  
          p:persistenceUnitName="ExamplePU"  
          p:persistenceXmlLocation="classpath:/META-INF/spring-persistence.xml"  
          p:jpaVendorAdapter-ref="jpaVendorAdapter"  
          p:jpaDialect-ref="jpaDialect"  
          p:dataSource-ref="dataSource"/> 

What happens is that by renaming the file JBoss won't validate it, since you are working outside of the EJB spec and not using any EJB beans, JBoss shouldn't be scanning this file anyways. And since you renamed it, you need to tell spring where it is and under what name.


I got it working by removing transaction-type="RESOURCE_LOCAL" and changing java:hmc to java:/hmc. But now my application has another problem whenever I try to persist.

It throws : java.lang.IllegalStateException: A JTA EntityManager cannot use getTransaction()

Can anybody tell me how to get a connection and start transaction in JTA mode?

Regards,

Satya

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜