HHH-4712 - Fix identifier column mappings when entities use non-identifier properties named id.

This commit is contained in:
Chris Cranford 2016-12-21 21:15:18 -05:00
parent 1f090f3731
commit f26488bc85
2 changed files with 19 additions and 12 deletions

View File

@ -341,14 +341,7 @@ public class FromElement extends HqlSqlWalkerNode implements DisplayableNode, Pa
throw new IllegalStateException( "No table alias for node " + this );
}
final String propertyName;
if ( getEntityPersister() != null && getEntityPersister().getEntityMetamodel() != null
&& getEntityPersister().getEntityMetamodel().hasNonIdentifierPropertyNamedId() ) {
propertyName = getEntityPersister().getIdentifierPropertyName();
}
else {
propertyName = EntityPersister.ENTITY_ID;
}
final String propertyName = getIdentifierPropertyName();
if ( getWalker().getStatementType() == HqlSqlTokenTypes.SELECT ) {
return getPropertyMapping( propertyName ).toColumns( table, propertyName );
@ -536,6 +529,10 @@ public class FromElement extends HqlSqlWalkerNode implements DisplayableNode, Pa
return elementType.getCollectionPropertyReference( propertyName );
}
public String getIdentifierPropertyName() {
return elementType.getIdentifierPropertyName();
}
public void setFetch(boolean fetch) {
this.fetch = fetch;
// Fetch can't be used with scroll() or iterate().

View File

@ -129,10 +129,10 @@ class FromElementType {
*/
String renderScalarIdentifierSelect(int i) {
checkInitialized();
String[] cols = getPropertyMapping( EntityPersister.ENTITY_ID ).toColumns(
getTableAlias(),
EntityPersister.ENTITY_ID
);
final String idPropertyName = getIdentifierPropertyName();
String[] cols = getPropertyMapping( idPropertyName ).toColumns( getTableAlias(), idPropertyName );
StringBuilder buf = new StringBuilder();
// For property references generate <tablealias>.<columnname> as <projectionalias>
for ( int j = 0; j < cols.length; j++ ) {
@ -677,4 +677,14 @@ class FromElementType {
return queryableCollection.toColumns( propertyName );
}
}
public String getIdentifierPropertyName() {
if ( getEntityPersister() != null && getEntityPersister().getEntityMetamodel() != null
&& getEntityPersister().getEntityMetamodel().hasNonIdentifierPropertyNamedId() ) {
return getEntityPersister().getIdentifierPropertyName();
}
else {
return EntityPersister.ENTITY_ID;
}
}
}