Archive

Posts Tagged ‘components.xml’

Error loading element EntityTransaction with component name null and component class null

30 November 2010 8 comments

The exception java.lang.RuntimeException: Error loading element EntityTransaction with component name null and component class null is caused by this line

<transaction:entity-transaction entity-manager="#{entityManager}"/>

in the components.xml file. In order to fix the error you have to replace the

   <persistence:managed-persistence-context name="entityManager" auto-create="true" persistence-unit-jndi-name="java:/myManagerFactory"/>

with

   <persistence:entity-manager-factory name="entityManagerFactory" persistence-unit-name="myPersistenceUnit"/>
   <persistence:managed-persistence-context name="entityManager" auto-create="true" entity-manager-factory="#{entityManagerFactory}" />

and remove the

<transaction:entity-transaction entity-manager="#{entityManager}"/>

line.

The myPersistenceUnit is the name of the persistence unit in persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence 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_1_0.xsd" 
             version="1.0">
             
   <persistence-unit name="myPersistenceUnit" transaction-type="RESOURCE_LOCAL">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>

      <jta-data-source>myDatasource</jta-data-source>

      <properties>
         <property name="hibernate.connection.provider_class" value="org.hibernate.connection.DatasourceConnectionProvider"/>
	   <property name="hibernate.connection.datasource" value="myDatasource"/>
	   <property name="transaction.factory_class" value="org.hibernate.transaction.JTATransactionFactory"/>
	   <property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/>
	   <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.WeblogicTransactionManagerLookup"/>
         <property name="hibernate.dialect" value="gr.my.company.util.MyAS400Dialect"/>
         <property name="hibernate.hbm2ddl.auto" value="validate"/>
         <property name="hibernate.show_sql" value="true"/>
         <property name="hibernate.format_sql" value="true"/>
         <property name="hibernate.default_schema" value="MYSCHEMA"/>
      </properties>
   </persistence-unit>  
    
</persistence>