Note that there are some explanatory texts on larger screens.

plurals
  1. POGeneric callback methods(@PostLoad..) for inherited entity classes - JPA EclipseLink
    text
    copied!<p>My entity class hierarchy is as follows.. <strong>ClassB</strong> which extends <strong>ClassA</strong> which extends abstract mappedsuperclass <strong>AbstractClass</strong></p> <p><strong>AbstractClass</strong></p> <pre><code>@MappedSuperclass public abstract class AbstractClass implements Serializable { } </code></pre> <p><strong>ClassA</strong></p> <pre><code>@Table(name = "TABLE_ONE") @SecondaryTable(name = "TABLE_TWO", @Inheritance(strategy=InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name="Type", discriminatorType=DiscriminatorType.STRING) @DiscriminatorValue("ClassA") public class ClassA extends AbstractClass { @Column(name = "CLASSA_XML") private String ClassAXML; @PrePersist @PreUpdate public void covertObjectToXml() { this.ClassAXML= JAXBUtilities.marshal(Object); } @PostLoad public void convertXmlToObject() { //does unmarshal } } </code></pre> <p><strong>ClassB</strong></p> <pre><code>@DiscriminatorValue("ClassB") public class ClassB extends ClassA { @Column(name = "CLASSB_XML", table = "TABLE_TWO") private String ClassBXML; @PrePersist @PreUpdate public void covertObjectToXml() { this.ClassAXML= JAXBUtilities.marshal(Object); } @PostLoad public void convertXmlToObject() { //does unmarshal } } </code></pre> <p>Problem : when i persist using ClassB entity. ClassA callback methods are not called and value in my classAXml attribute is not persisted.</p> <p>Is there anyway to generalize <strong>callback method</strong>(i.e covertObjectToXml and convertXmlToObject) for my inherited entity class structure.. so that <strong>when i persist using both ClassA and ClassB individually</strong>, my callback methods are called respectively based on inheritance and their values can be persisted.</p> <p>Note: </p> <ol> <li>I have removed the callback methods from ClassA and generalize it in classB and persist but my requirement is mainly individual persistent of classA and ClassB.</li> <li>my call back methods should not be in mapedSuperClass i.e AbstractClass.</li> </ol> <p>Thanks in advance</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload