Announcement Announcement Module
Collapse
No announcement yet.
Hibernate Event Listeners not called after using Merging Persistence Unit Manager Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Hibernate Event Listeners not called after using Merging Persistence Unit Manager

    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.

    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.



    <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="1000" />
    <property name="hibernate.cache.use_second_level_cache" value="true" />
    <property name="hibernate.cache.use_query_cache" value="true" />
    <property name="hibernate.cache.use_structured_entries" value="true" />
    <property name="hibernate.cache.region.factory_class" value="net.sf.ehcache.hibernate.SingletonEhCacheRe gionFactory" />
    <property name="hibernate.cache.provider_configuration_file_ resource_path" value="/ehcache.xml" />

    <property name="hibernate.ejb.event.pre-update" value="com......dao.listener.ChangeHistoryMultiSel ectListener" />
    <property name="hibernate.ejb.event.pre-insert" value="com......dao.listener.LMCoreEntityAuditList ener" />

    <!-- General Debugging -->
    <property name="hibernate.show_sql" value="false" />
    <property name="hibernate.format_sql" value="true" />
    <property name="hibernate.generate_statistics" value="true" />
    </properties>
    </persistence-unit>

    The second persistence.xml is just this

    <persistence-unit name="LineManagement" transaction-type="RESOURCE_LOCAL">
    </persistence-unit>

    I realised that after i started using the MergingPersistenceUnitManager my listeners are never called...
    Here is a snippet from one of them.

    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<String> props = Arrays.asList(event.getPersister().getPropertyName s());
    event.getState()[props.indexOf(CREATED_BY)] = user;
    event.getState()[props.indexOf(MODIFIED_BY)] = user;
    }

    return false;
    }


    Any help would be greatly appreciated. Maybe i am missing something basic. The dependencies are properly configured with me using Spring-data-jpa 1.0.3 and Spring 3.0.5, with Hibernate-entitymanager 3.6.5.Final
Working...
X