4

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?

Naveed S
  • 5,106
  • 4
  • 34
  • 52
  • Err, add the needed columns to the table. If ABC extends XYZ, it IS an XYZ, and all the fields of XYZ are thus necessary in the table. If they're not necessary, then you shouldn't have ABC extend XYZ. – JB Nizet Jan 09 '12 at 09:10
  • ABC is not the only class extending XYZ – Naveed S Jan 09 '12 at 09:27
  • So what? My point remains. If you have the same problem with other extending classes, then they shouldn't extend XYZ either. – JB Nizet Jan 09 '12 at 09:34
  • JPA doesn't mention support for inherited embedded objects; a discriminator would be needed to provide such a feature. Was added to JDO spec recently. – DataNucleus Jan 09 '12 at 14:23

3 Answers3

1

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'.

Ramsharan
  • 2,054
  • 2
  • 22
  • 26
0

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)

user1799339
  • 65
  • 1
  • 5
0

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.

James
  • 17,965
  • 11
  • 91
  • 146