Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Jpa prepersist callback not called on parent
icon4.gif  Jpa prepersist callback not called on parent [message #1433215] Sun, 28 September 2014 11:30 Go to next message
kraken kraken is currently offline kraken krakenFriend
Messages: 3
Registered: January 2013
Junior Member
My code
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class SiteMessage implements Identifiable{
    @PrePersist
    public void onCreate1(){
        System.out.println("Executed onCreate1");
    }
}

@Entity
@Table(name = "feedback")
public class Feedback extends SiteMessage {
    @PrePersist
    public void onCreate2(){
        System.out.println("Executed onCreate2");
    }
}


When i save Feedback entity i expect that i will see: Executed onCreate1 and Executed onCreate2, but i've seen only Executed onCreate2

I've created a test repo: https:// github.com/ SunPj/ eclipselink-h2-jpa
(please remove spaces from url, sorry, i don't have permission to add a link to post)

[Updated on: Sun, 28 September 2014 11:31]

Report message to a moderator

Re: Jpa prepersist callback not called on parent [message #1435680 is a reply to message #1433215] Wed, 01 October 2014 21:09 Go to previous messageGo to next message
Rick Curtis is currently offline Rick CurtisFriend
Messages: 24
Registered: September 2014
Location: Rochester, MN
Junior Member
I'd suggest opening a bug on https://bugs.eclipse.org/bugs/enter_bug.cgi .
Re: Jpa prepersist callback not called on parent [message #1435955 is a reply to message #1435680] Thu, 02 October 2014 07:25 Go to previous messageGo to next message
Michele Mariotti is currently offline Michele MariottiFriend
Messages: 3
Registered: October 2014
Junior Member
In my opinion this could not be a bug, since multiple @PrePersist are forbidden for the same entity, and @PrePersist annotation has not been marked @Inherited.

Probably you already know, but the correct ways to achieve this are:

@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@EntityListeners(SiteMessageListener.class)
public class SiteMessage implements Identifiable{

}

@Entity
@Table(name = "feedback")
@EntityListeners({ SiteMessageListener.class, FeedbackListener.class })
public class Feedback extends SiteMessage {

}


or

@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class SiteMessage implements Identifiable{
    @PrePersist
    public void onCreate(){
        System.out.println("Executed onCreate1");
    }
}

@Entity
@Table(name = "feedback")
public class Feedback extends SiteMessage {
    @PrePersist
    @Override
    public void onCreate(){
        super.onCreate();
        System.out.println("Executed onCreate2");
    }
}
Re: Jpa prepersist callback not called on parent [message #1436233 is a reply to message #1435955] Thu, 02 October 2014 15:43 Go to previous messageGo to next message
Rick Curtis is currently offline Rick CurtisFriend
Messages: 24
Registered: September 2014
Location: Rochester, MN
Junior Member
Michele Mariotti wrote on Thu, 02 October 2014 07:25
In my opinion this could not be a bug, since multiple @PrePersist are forbidden for the same entity, and @PrePersist annotation has not been marked @Inherited.


Sorry, but I don't think you're quite right. While yes, the spec does say that for a given class you cannot have more than one lifecycle callback method for the same lifecycle event, that isn't the 'real' problem that the op has reported.

The problem does not have anything to do with multiple @PrePersist annotations(which is valid btw) in an inheritance hierarchy. The problem is that when the op persists a Feedback(child), the parent @PrePersist never is called. If you were to remove the @PrePersist from Feedback the problem still is the same.

I still assert that this is a bug.
Re: Jpa prepersist callback not called on parent [message #1437364 is a reply to message #1436233] Sat, 04 October 2014 08:41 Go to previous message
Michele Mariotti is currently offline Michele MariottiFriend
Messages: 3
Registered: October 2014
Junior Member
You are right, this is a bug. This behavior does not respect JPA 2.1 spec, par 3.5.5 and 3.5.6.
Previous Topic:Eclipselink 2.5.2 giving exception on executing jpql having CASE expression
Next Topic:problem with embedded object
Goto Forum:
  


Current Time: Tue Mar 19 07:10:35 GMT 2024

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

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

Back to the top