Note that there are some explanatory texts on larger screens.

plurals
  1. POHibernate Event Listeners not called after using Merging Persistence Unit Manager
    primarykey
    data
    text
    <p>i have a component which was developed and added as a dependency to our project... i need to use the entity specified in that component and inorder to do that i had to use the MergingPersistenceUnitManager from the Spring data-jpa project. This component defines a persistence.xml which has the unitName same as the parent project in which it is used. Now, i have two persistence.xml files and both are loaded during the EntityManagerFactory creation using the MergingPersistenceUnitManager. </p> <p>Everything works fine and the Entity is loaded and detected during container startup... However the problem that i face here is, that my declared hibernate listeners arent called at all.. They never seem to be invoked, and i have verified that they work if i remove the component and have only one persistence.xml file. </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="1000" /&gt; &lt;property name="hibernate.cache.use_second_level_cache" value="true" /&gt; &lt;property name="hibernate.cache.use_query_cache" value="true" /&gt; &lt;property name="hibernate.cache.use_structured_entries" value="true" /&gt; &lt;property name="hibernate.cache.region.factory_class" value="net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory" /&gt; &lt;property name="hibernate.cache.provider_configuration_file_resource_path" value="/ehcache.xml" /&gt; &lt;property name="hibernate.ejb.event.pre-update" value="com......dao.listener.ChangeHistoryMultiSelectListener" /&gt; &lt;property name="hibernate.ejb.event.pre-insert" value="com......dao.listener.LMCoreEntityAuditListener" /&gt; &lt;!-- General Debugging --&gt; &lt;property name="hibernate.show_sql" value="false" /&gt; &lt;property name="hibernate.format_sql" value="true" /&gt; &lt;property name="hibernate.generate_statistics" value="true" /&gt; &lt;/properties&gt; &lt;/persistence-unit&gt; </code></pre> <p>The second persistence.xml is just this</p> <pre><code> &lt;persistence-unit name="LineManagement" transaction-type="RESOURCE_LOCAL"&gt; &lt;/persistence-unit&gt; </code></pre> <p>I realised that after i started using the MergingPersistenceUnitManager my listeners are never called... Here is a snippet from one of them.</p> <pre><code>public class LMCoreEntityAuditListener implements PreInsertEventListener, PreUpdateEventListener, Initializable { private static final String MODIFIED_BY = "modifiedBy"; private static final String CREATED_BY = "createdBy"; @Override public boolean onPreInsert(final PreInsertEvent event) { System.out.println("ssss"); if (!(event.getEntity() instanceof LMBaseEntity)) { return false; } final LMBaseEntity entity = (LMBaseEntity) event.getEntity(); if (!(entity instanceof GlobalLine) || (entity.getCreatedTimestamp() == null)) { // auditCreates(entity); final String user = SecurityContextUtil.getOriginalUser(); final List&lt;String&gt; props = Arrays.asList(event.getPersister().getPropertyNames()); event.getState()[props.indexOf(CREATED_BY)] = user; event.getState()[props.indexOf(MODIFIED_BY)] = user; } return false; } </code></pre> <p>Any help would be greatly appreciated. Maybe i am missing something basic. The dependencies are properly configured. </p>
    singulars
    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.
    1. This table or related slice is empty.
    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