Hi Stefan. Finally I have it working.
These are my files:
persistence.xml
Code:
<persistence-unit name="persistenceUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<!--value='create' to build a new database on each run; value='update' to modify an existing database; value='create-drop' means the same as 'create' but also drops tables when Hibernate closes; value='validate' makes no changes to the database-->
<property name="hibernate.hbm2ddl.auto" value="create"/>
<property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy"/>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/dpm" />
<property name="hibernate.connection.username" value="root" />
<property name="hibernate.connection.password" value="123456" />
</properties>
</persistence-unit>
<persistence-unit name="persistenceUnitEW" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<!--value='create' to build a new database on each run; value='update' to modify an existing database; value='create-drop' means the same as 'create' but also drops tables when Hibernate closes; value='validate' makes no changes to the database-->
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy"/>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/2010ac" />
<property name="hibernate.connection.username" value="root" />
<property name="hibernate.connection.password" value="123456" />
</properties>
</persistence-unit>
aplicationContext.xml
Code:
<context:property-placeholder location="classpath*:META-INF/spring/*.properties"/>
<context:spring-configured/>
<context:component-scan base-package="es.grupoduo.dpm">
<context:exclude-filter expression=".*_Roo_.*" type="regex"/>
<context:exclude-filter expression="org.springframework.stereotype.Controller" type="annotation"/>
</context:component-scan>
<bean id="pum" class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
<property name="persistenceXmlLocations">
<list>
<value>classpath*:META-INF/persistence.xml</value>
</list>
</property>
</bean>
<bean class="org.springframework.orm.jpa.JpaTransactionManager" id="transactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<bean class="org.springframework.orm.jpa.JpaTransactionManager" id="transactionManagerEW">
<property name="entityManagerFactory" ref="entityManagerFactoryEW"/>
</bean>
<tx:annotation-driven mode="aspectj" transaction-manager="transactionManager"/>
<tx:annotation-driven mode="aspectj" transaction-manager="transactionManagerEW"/>
<bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="entityManagerFactory">
<property name="persistenceUnitManager" ref="pum"/>
<property name="persistenceUnitName" value="persistenceUnit" />
</bean>
<bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="entityManagerFactoryEW">
<property name="persistenceUnitManager" ref="pum"/>
<property name="persistenceUnitName" value="persistenceUnitEW" />
</bean>
One entity:
Code:
@Entity
@RooJavaBean
@RooToString
@RooEntity(identifierColumn = "CODIGO")
@Table(name = "clientes")
public class Cliente {
@NotNull
private String nombre;
@PersistenceContext(unitName="persistenceUnitEW")
transient EntityManager entityManager;
}
Thanks