@@ -131,31 +131,36 @@ private ForeignKeyDirection getForeignKeyDirection() {
131
131
return !isEmptyAnnotationValue ( mappedBy ) ? ForeignKeyDirection .TO_PARENT : ForeignKeyDirection .FROM_PARENT ;
132
132
}
133
133
134
- private void bindOwned (Map <String , PersistentClass > persistentClasses , OneToOne value , Property property ) {
135
- value .setMappedByProperty ( mappedBy );
136
- final PersistentClass targetEntity = persistentClasses .get ( value .getReferencedEntityName () );
134
+ private void bindOwned (Map <String , PersistentClass > persistentClasses , OneToOne oneToOne , Property property ) {
135
+ oneToOne .setMappedByProperty ( mappedBy );
136
+ final PersistentClass targetEntity = persistentClasses .get ( oneToOne .getReferencedEntityName () );
137
137
if ( targetEntity == null ) {
138
138
throw new MappingException ( "Association '" + getPath ( propertyHolder , inferredData )
139
- + "' targets unknown entity type '" + value .getReferencedEntityName () + "'" );
139
+ + "' targets unknown entity type '" + oneToOne .getReferencedEntityName () + "'" );
140
140
}
141
- final Property targetProperty = targetProperty ( value , targetEntity );
141
+ if ( !oneToOne .isLazyPolymorphismAllowed () && oneToOne .isLazy () && targetEntity .hasSubclasses () ) {
142
+ throw new AnnotationException ( "Association '" + getPath ( propertyHolder , inferredData )
143
+ + "' is annotated '@Proxyless' but targets an entity named '"
144
+ + oneToOne .getReferencedEntityName () + "' which has subclasses" );
145
+ }
146
+ final Property targetProperty = targetProperty ( oneToOne , targetEntity );
142
147
if ( targetProperty .getValue () instanceof OneToOne ) {
143
148
propertyHolder .addProperty ( property , inferredData .getDeclaringClass () );
144
149
}
145
150
else if ( targetProperty .getValue () instanceof ManyToOne ) {
146
- bindTargetManyToOne ( persistentClasses , value , property , targetEntity , targetProperty );
151
+ bindTargetManyToOne ( persistentClasses , oneToOne , property , targetEntity , targetProperty );
147
152
}
148
153
else {
149
154
throw new AnnotationException ( "Association '" + getPath ( propertyHolder , inferredData )
150
155
+ "' is 'mappedBy' a property named '" + mappedBy
151
- + "' of the target entity type '" + value .getReferencedEntityName ()
156
+ + "' of the target entity type '" + oneToOne .getReferencedEntityName ()
152
157
+ "' which is not a '@OneToOne' or '@ManyToOne' association" );
153
158
}
154
159
}
155
160
156
161
private void bindTargetManyToOne (
157
162
Map <String , PersistentClass > persistentClasses ,
158
- OneToOne value ,
163
+ OneToOne oneToOne ,
159
164
Property property ,
160
165
PersistentClass targetEntity ,
161
166
Property targetProperty ) {
@@ -174,11 +179,11 @@ private void bindTargetManyToOne(
174
179
final ManyToOne manyToOne = new ManyToOne ( buildingContext , mappedByJoin .getTable () );
175
180
//FIXME use ignore not found here
176
181
manyToOne .setNotFoundAction ( notFoundAction );
177
- manyToOne .setCascadeDeleteEnabled ( value .isCascadeDeleteEnabled () );
178
- manyToOne .setFetchMode ( value .getFetchMode () );
179
- manyToOne .setLazy ( value .isLazy () );
180
- manyToOne .setReferencedEntityName ( value .getReferencedEntityName () );
181
- manyToOne .setUnwrapProxy ( value .isUnwrapProxy () );
182
+ manyToOne .setCascadeDeleteEnabled ( oneToOne .isCascadeDeleteEnabled () );
183
+ manyToOne .setFetchMode ( oneToOne .getFetchMode () );
184
+ manyToOne .setLazy ( oneToOne .isLazy () );
185
+ manyToOne .setReferencedEntityName ( oneToOne .getReferencedEntityName () );
186
+ manyToOne .setUnwrapProxy ( oneToOne .isUnwrapProxy () );
182
187
manyToOne .markAsLogicalOneToOne ();
183
188
property .setValue ( manyToOne );
184
189
for ( Column column : otherSideJoin .getKey ().getColumns () ) {
@@ -203,7 +208,7 @@ private void bindTargetManyToOne(
203
208
propertyHolder .addProperty ( property , inferredData .getDeclaringClass () );
204
209
}
205
210
206
- value .setReferencedPropertyName ( mappedBy );
211
+ oneToOne .setReferencedPropertyName ( mappedBy );
207
212
208
213
// HHH-6813
209
214
// Foo: @Id long id, @OneToOne(mappedBy="foo") Bar bar
@@ -212,16 +217,16 @@ private void bindTargetManyToOne(
212
217
boolean referenceToPrimaryKey = mappedBy == null
213
218
|| targetEntityIdentifier instanceof Component
214
219
&& !( (Component ) targetEntityIdentifier ).hasProperty ( mappedBy );
215
- value .setReferenceToPrimaryKey ( referenceToPrimaryKey );
220
+ oneToOne .setReferenceToPrimaryKey ( referenceToPrimaryKey );
216
221
217
- final String propertyRef = value .getReferencedPropertyName ();
222
+ final String propertyRef = oneToOne .getReferencedPropertyName ();
218
223
if ( propertyRef != null ) {
219
224
buildingContext .getMetadataCollector ()
220
- .addUniquePropertyReference ( value .getReferencedEntityName (), propertyRef );
225
+ .addUniquePropertyReference ( oneToOne .getReferencedEntityName (), propertyRef );
221
226
}
222
227
}
223
228
224
- private Property targetProperty (OneToOne value , PersistentClass targetEntity ) {
229
+ private Property targetProperty (OneToOne oneToOne , PersistentClass targetEntity ) {
225
230
try {
226
231
Property targetProperty = findPropertyByName ( targetEntity , mappedBy );
227
232
if ( targetProperty != null ) {
@@ -233,10 +238,10 @@ private Property targetProperty(OneToOne value, PersistentClass targetEntity) {
233
238
}
234
239
throw new AnnotationException ( "Association '" + getPath ( propertyHolder , inferredData )
235
240
+ "' is 'mappedBy' a property named '" + mappedBy
236
- + "' which does not exist in the target entity type '" + value .getReferencedEntityName () + "'" );
241
+ + "' which does not exist in the target entity type '" + oneToOne .getReferencedEntityName () + "'" );
237
242
}
238
243
239
- private void bindUnowned (Map <String , PersistentClass > persistentClasses , OneToOne value , String propertyName , Property property ) {
244
+ private void bindUnowned (Map <String , PersistentClass > persistentClasses , OneToOne oneToOne , String propertyName , Property property ) {
240
245
// we need to check if the columns are in the right order
241
246
// if not, then we need to create a many to one and formula
242
247
// but actually, since entities linked by a one to one need
@@ -245,16 +250,16 @@ private void bindUnowned(Map<String, PersistentClass> persistentClasses, OneToOn
245
250
246
251
if ( rightOrder ) {
247
252
final ToOneFkSecondPass secondPass = new ToOneFkSecondPass (
248
- value ,
253
+ oneToOne ,
249
254
joinColumns ,
250
255
!optional , //cannot have nullable and unique on certain DBs
251
256
propertyHolder .getPersistentClass (),
252
257
qualify ( propertyHolder .getPath (), propertyName ),
253
258
buildingContext
254
259
);
255
260
secondPass .doSecondPass (persistentClasses );
256
- //no column associated since its a one to one
257
- propertyHolder .addProperty (property , inferredData .getDeclaringClass () );
261
+ //no column associated since it's a one to one
262
+ propertyHolder .addProperty ( property , inferredData .getDeclaringClass () );
258
263
}
259
264
// else {
260
265
// this is a @ManyToOne with Formula
0 commit comments