Hello
I am having some trouble trying to make a shared Embeddedable
class to work across different classes having some FK column names
overridden.
This is model:
@Embeddable
class Location {
@Enumerated
private LocationType locationType;
@ManyToOne
@JoinColumn(name="co_state", referencedColumnName="co_state")
private State state;
@ManyToOne
@JoinColumn(name="co_city")
private City city;
@ManyToOne //Composite PK
@JoinColumns(
@JoinColumn(name="co_unit", referencedColumnName="co_unit"),
@JoinColumn(name="co_city", referencedColumnName="co_city", insertable=false, updatable=false)
)
private LocalUnit unit;
}
@Entity
@Table(name="TB_NOTIFICATOR")
class Notificator {
@Embedded
@AssociationOverrides({
@AssociationOverride(name="state", joinColumns=@JoinColumn(name = "co_source_state", referencedColumnName = "co_state")),
@AssociationOverride(name="city", joinColumns=@JoinColumn(name = "co_source_city", referencedColumnName = "co_city")),
@AssociationOverride(name="unit", joinColumns={
@JoinColumn(name = "co_source_unit", referencedColumnName = "co_unit"),
@JoinColumn(name = "co_source_city", referencedColumnName = "co_city", updatable=false, insertable=false) }),
})
private Location sourceLocation;
@ManyToOne //Different from the one inside source location
@JoinColumns(
@JoinColumn(name="co_unit"),
@JoinColumn(name="co_city", insertable=false, updatable=false)
)
private LocalUnit notificatorUnit;
Then i have another class called Message, which has "origin" and
"destination" embedded attributes of Location type following the same
AssociationOverrides logic, but of course with a bit different names.
Honestly it looks fine to me, but when i try to start the context i get this error:
Exception [EclipseLink-93] (Eclipse Persistence Services - 2.5.2.v20131113- a7346c6): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The table [TB_NOTIFICATOR] is not present in this descriptor.
Descriptor: RelationalDescriptor(common.location.City --> [DatabaseTable(TB_CITY)])
Exception [EclipseLink-93] (Eclipse Persistence Services - 2.5.2.v20131113- a7346c6): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The table [TB_MESSAGE] is not present in this descriptor.
Descriptor: RelationalDescriptor(common.location.City --> [DatabaseTable(TB_CITY)])
I tried to remove the city attribute from Location class, but then
the error starts to be thrown for the "unit" attribute and TB_UNIT
table.
Any thoughts on how to make it works?
Thanks