Note that there are some explanatory texts on larger screens.

plurals
  1. POLoading JPA Entity from external Jar file
    primarykey
    data
    text
    <p>i have a project setup where i have modularized a project, and packaged a module into a jar file which gets included in the main project when we create a war and deploy it. The problem that i am facing is that, i have an Entity present in the module which does not load when the JPA Container EntityManagerFactory for the unitName is built during startup. </p> <p>The basic question that i have is doesnt the EntityManager lookup at the persistence.xml and then load the properties that are specified, and then scan all the packages for @Entity annotation? </p> <p>Any insight on how this works and how can i resolve this would be great. </p> <p>I found this link and it mentions about creating seperate persistenceUnits, but here i dont need a seperate persistence unit. i just need the module to piggy back on the parent project and load the entity and any other @Resource, @Component classes, which it does due to the context:component scan and the annotation config. </p> <p><a href="http://javathoughts.capesugarbird.com/2009/02/jpa-and-multiple-persistence-units.html">http://javathoughts.capesugarbird.com/2009/02/jpa-and-multiple-persistence-units.html</a></p> <p>Here is my code/configuration</p> <pre><code>&lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt; &lt;property name="dataSource" ref="dataSource" /&gt; &lt;property name="persistenceUnitName" value="LineManagement" /&gt; &lt;property name="jpaVendorAdapter"&gt; &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"&gt; &lt;property name="generateDdl" value="false" /&gt; &lt;property name="showSql" value="false" /&gt; &lt;property name="databasePlatform" ref="cpsHibernateDialectClassName" /&gt; &lt;/bean&gt; &lt;/property&gt; &lt;property name="beanName" value="entityManager"&gt;&lt;/property&gt; &lt;/bean&gt; </code></pre> <p>definition of the EnitityManagerFactory to startup the Entity Manager. </p> <pre><code>&lt;persistence-unit name="LineManagement" transaction-type="RESOURCE_LOCAL"&gt; &lt;properties&gt; &lt;property name="hibernate.id.new_generator_mappings" value="true" /&gt; &lt;property name="hibernate.current_session_context_class" value="thread" /&gt; &lt;property name="hibernate.default_batch_fetch_size" value="200" /&gt; </code></pre> <p>....</p> <p>Persistence.xml which defines the second level cache and other hibernate properties. </p> <p>Then, the module which has an entity.</p> <pre><code>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 { </code></pre> <p>.... }</p> <p>Note: the entity is in a different package than the parent, since it is a seperate module on its own. </p> <p>The entity which loads fine in the main project. </p> <pre><code>package com.parent.line.entity; import javax.persistence.Entity; @Entity @Table(name = "ACCOUNT") @Cacheable(true) public class Account implements LMLookupTypeEntityByDivision, Serializable, Comparable&lt;Account&gt; { </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload