Extending Embeddable class in JPA

1.5k views Asked by At

I have an embeddable class ABC extended from another embeddable class XYZ. ABC's object is embedded in an entity. The table corresponding to the entity contains only elements of ABC and not of XYZ. What should I do to get them also?

I have heard that Descriptor Customizer will work. How should I do that? Is there any other way?

3

There are 3 answers

0
James On

You need to set the InheritancePolicy classIndicatorField in your DescriptorCustomizer for XYZ. Then you need to define the aggregate descriptor for ABC that extends XYZ, you may need a SessionCustomizer for that.

0
Ramsharan On

This document of oracle javaEE might help you. According to this, InheritanceType.SINGLE_TABLE is default strategy. You may need InheritanceType.TABLE_PER_CLASS for your requirement.

It has described it in Entity Inheritance Mapping Strategies topic but I believe that it may also work for 'Embeddable'.

0
user1799339 On

Can someone give an example for how to write this DescriptorCustomizer? I have the same thing my XYZ class has a bunch of strings and uids. I can't get the object that has the embedded ABC to show the fields from XYZ. (The only way I was able to do it is to put getters in ABC for all of XYZs fields and that no good)