Skip to main content



      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 07:30 Go to next message
Eclipse UserFriend
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 07:31] by Moderator

Re: Jpa prepersist callback not called on parent [message #1435680 is a reply to message #1433215] Wed, 01 October 2014 17:09 Go to previous messageGo to next message
Eclipse UserFriend
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 03:25 Go to previous messageGo to next message
Eclipse UserFriend
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 11:43 Go to previous messageGo to next message
Eclipse UserFriend
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 04:41 Go to previous message
Eclipse UserFriend
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 Jul 15 23:33:01 EDT 2025

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

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

Back to the top