I have a project where I simulated a project and packaged the module into a jar file, which is included in the main project when we create a war and deploy it. The problem I am facing is that I have an Entity present in a module that does not load when the JPA Container EntityManagerFactory for unitName is created at startup time.
The main question I have is not looking for the EntityManager in the persistence.xml file, and then loading the specified properties and then scanning all the packages for @Entity annotation?
Any insight into how this works and how I can solve it would be great.
I found this link and mentions the creation of separate persistenceUnits constants, but here I do not need a separate persistence unit. I just need this module to go back to the parent project and load the object and any other @Resource, @Component classes that it executes because of context: checking the components and configuring the annotation.
http://javathoughts.capesugarbird.com/2009/02/jpa-and-multiple-persistence-units.html
Here is my code / configuration
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="persistenceUnitName" value="LineManagement" /> <property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> <property name="generateDdl" value="false" /> <property name="showSql" value="false" /> <property name="databasePlatform" ref="cpsHibernateDialectClassName" /> </bean> </property> <property name="beanName" value="entityManager"></property> </bean>
Defining EnitityManagerFactory to launch Entity Manager.
<persistence-unit name="LineManagement" transaction-type="RESOURCE_LOCAL"> <properties> <property name="hibernate.id.new_generator_mappings" value="true" /> <property name="hibernate.current_session_context_class" value="thread" /> <property name="hibernate.default_batch_fetch_size" value="200" />
....
Persistence.xml, which defines the second level cache and other hibernate properties.
Then the module that has the entity.
import javax.persistence.Entity; @Entity @Table(name = IntegrationEvent.TABLE_NAME, uniqueConstraints = @UniqueConstraint(columnNames = "INTGRTN_EVNT_QUEUE_SK")) @GenericGenerator(name = "UUID_GEN", strategy = "org.hibernate.id.UUIDHexGenerator", parameters = { @Parameter(name = "separator", value = "-") }) public class IntegrationEvent implements Serializable {
....}
Note: the object is in a different package than the parent, because it is a separate module on its own.
The object that is being loaded in the main project.
package com.parent.line.entity; import javax.persistence.Entity; @Entity @Table(name = "ACCOUNT") @Cacheable(true) public class Account implements LMLookupTypeEntityByDivision, Serializable, Comparable<Account> {