Skip to main content


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 22:24 Go to next message
Andy Clan is currently offline Andy ClanFriend
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
Re: Help, default entity listeners not being invoked [message #536950 is a reply to message #536083] Mon, 31 May 2010 15:55 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

There seems to be a bug that if a descriptor does not have any event listeners, then the default event listeners are not triggered.

Please log this bug and vote for it.

A workaround would be to define a SessionCustomizer that iterates over all of the ClassDescriptors and adds a dummy DescriptorEventListener to their eventManagers.


James : Wiki : Book : Blog : Twitter
Re: Help, default entity listeners not being invoked [message #537022 is a reply to message #536950] Tue, 01 June 2010 01:51 Go to previous messageGo to next message
Andy Clan is currently offline Andy ClanFriend
Messages: 4
Registered: May 2010
Junior Member
Thanks for taking a look at this James. I have logged it as a bug, Bug 315154.

Am more than a little surprised that this bug exists as its reproducible with little more than 20 lines of code. I would have thought this might also be something that a lot of people would want to implement, (application wide logging and debugging listeners etc).

Its also drawn from code out of Antonio Goncalves book JavaEE6 with Glassfish (chap 05) which I am making my way through. I would have thought there'd be a lot of readers who'd also come across it because of this too.

andy
Re: Help, default entity listeners not being invoked [message #651093 is a reply to message #537022] Thu, 27 January 2011 17:43 Go to previous message
Haya Gur is currently offline Haya GurFriend
Messages: 2
Registered: January 2011
Junior Member
Thanks for sharing this bug. I have also encountered exactly the same problem, and couldn't figure out what's wrong. its not that surprising by the way, I have encountered some more problems and compilation errors when trying to follow this Antonio Goncalves's book...
Previous Topic:Unresolved generator name "foreign" ?
Next Topic:How to save data in different tables with one entity
Goto Forum:
  


Current Time: Fri Apr 19 07:56:05 GMT 2024

Powered by FUDForum. Page generated in 0.01788 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top