About Question enthuware.oce-jpad.v6.2.417 :

Moderator: admin

Post Reply
cosminvacaroiu

Re: About Question enthuware.oce-jpad.v6.2.417 :

Post by cosminvacaroiu »

Why is this true ?

Code: Select all

Since the cubeLocation field is defined within Employee class, the AssociationOverride annotation has to be applied directly to the field definition. Had the cubeLocation field been defined in a MappedSuper class of Employee (say, in Person), you would have to specify AssociationOverride annotation on the class.

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.oce-jpad.v6.2.417 :

Post by admin »

This is as per Section 11.1.2
When used to override a mapping defined by a mapped superclass, the AssociationOverride annotation is applied to the entity class.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.

Guest

Re: About Question enthuware.oce-jpad.v6.2.417 :

Post by Guest »

admin wrote:This is as per Section 11.1.2
When used to override a mapping defined by a mapped superclass, the AssociationOverride annotation is applied to the entity class.
HTH,
Paul.
Yeah but this doesn't say that the only time you're allowed to use AssociationOverride at Class level is with MappedSuperclass. You can use it there for this case also, but you have to use as prefix the name of the field in this class.

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.oce-jpad.v6.2.417 :

Post by admin »

Guest wrote:
admin wrote:This is as per Section 11.1.2
When used to override a mapping defined by a mapped superclass, the AssociationOverride annotation is applied to the entity class.
HTH,
Paul.
Yeah but this doesn't say that the only time you're allowed to use AssociationOverride at Class level is with MappedSuperclass. You can use it there for this case also, but you have to use as prefix the name of the field in this class.
Right, the explanation is not saying that either. The explanation is saying that if the field is defined in the mapped super class, you have to use the annotation at the class level. How can you specify the overrides on the field in the sub class if the field is not present there?
If you like our products and services, please help us by posting your review here.

__JJ__
Posts: 125
Joined: Thu Jul 05, 2018 6:44 pm
Contact:

Re: About Question enthuware.oce-jpad.v6.2.417 :

Post by __JJ__ »

You can use @AssociationOverride annotation on the owner side of the relationship (i.e. the Many side in a ManyToOne/OneToMany relationship, which is Employee in the case), to change the name of the foreign key column. For example: @AssociationOverride(          name="cubeLocation.mailBox",  //Observe that cubeLocation. is required only if the @AssociationOverride is applied on the class instead of the field because mailBox field is not present directly in Employee. It is accessible through cubeLocation.          joinColumns=@JoinColumn(name="MBX_ID")         )

Post Reply

Who is online

Users browsing this forum: No registered users and 24 guests