Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Help, default entity listeners not being invoked
Help, default entity listeners not being invoked [message #536083] Wed, 26 May 2010 18:24 Go to previous message
Andy Clan is currently offline Andy Clan
Messages: 4
Registered: May 2010
Junior Member
EclipseLink 2.0
Java SE 1.6.0_17

I am writing a simple global debug listener to output CRUD debug events on 4 simple entities. In the entity mappings XML file, I have the following:

    
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm
                                     http://java.sun.com/xml/ns/persistence/orm_2_0.xsd" version="2.0">
    <persistence-unit-metadata>
        <persistence-unit-defaults>
            <entity-listeners>
                <entity-listener class="bo.DebugListener">
                    <pre-persist method-name="prePersist"></pre-persist>
                    <post-persist method-name="postPersist"></post-persist>
                    <pre-remove method-name="preRemove"></pre-remove>
                    <post-remove method-name="postRemove"></post-remove>
                    <pre-update method-name="preUpdate"></pre-update>
                    <post-update method-name="postUpdate"></post-update>
                    <post-load method-name="postLoad"></post-load>
                </entity-listener>
            </entity-listeners>
        </persistence-unit-defaults>
    </persistence-unit-metadata>
</entity-mappings>


My DebugListener class just contains simple sys out calls as follows:


public class DebugListener {

    public DebugListener() {
        System.out.println(">>>>>>>>>>>>>>> CONSTRUCTOR");
    }

    public void prePersist(Object o) {
        System.out.println(">>>>>>>>>>>>>>> " + o.getClass() + " PREPERSIST");
    }

    public void postPersist(Object o) {
        System.out.println(">>>>>>>>>>>>>>> " + o.getClass() + " POSTPERSIST");
    }

    public void preUpdate(Object o) {
        System.out.println(">>>>>>>>>>>>>>> " + o.getClass() + " PREUPDATE");
    }

    public void postUpdate(Object o) {
        System.out.println(">>>>>>>>>>>>>>> " + o.getClass() + " POSTUPDATE");
    }

    public void preRemove(Object o) {
        System.out.println(">>>>>>>>>>>>>>> " + o.getClass() + " PREREMOVE");
    }

    public void postRemove(Object o) {
        System.out.println(">>>>>>>>>>>>>>> " + o.getClass() + " POSTREMOVE");
    }

    public void postLoad(Object o) {
        System.out.println(">>>>>>>>>>>>>>> " + o.getClass() + " POSTLOAD");
    }
}



I have 4 entities, several instances of which are inserted into an in-process Derby database (running in a Java SE environment), but the CRUD sys outs never get called. I do get 4 constructor sys outs, however.

Also, if I move the block of <entity-listener> XML into a section for any specific entity (under <entity class="...">), I do see all the CRUD sysouts for that entity.

I am thinking that the default entity listeners should be invoked on each and every entity registered into the persistence unit by default with the above XML and listener class. But I am new to JPA, so perhaps I have missed something here ?

Any help greatly appreciated. Smile
 
Read Message
Read Message
Read Message
Read Message
Previous Topic:Unresolved generator name "foreign" ?
Next Topic:How to save data in different tables with one entity
Goto Forum:
  


Current Time: Wed May 22 23:41:08 EDT 2013

Powered by FUDForum. Page generated in 0.03712 seconds