Hibernate - CriteriaBuilderImpl - method treat()

Description

In WildFly 11 Hibernate was updated from 5.0.7.Final to 5.1.10.Final.

In new Hibernate "joins.add( treatAs );" adds extra JOIN to database query, so every row appears twice in result.

Hibernate 5.0.7.Final

public <X, T, V extends T> Join<X, V> treat(Join<X, T> join, Class<V> type) {
return ( (JoinImplementor) join ).treatAs( type );
}

Hibernate 5.1.10.Final

public <X, T, V extends T> Join<X, V> treat(Join<X, T> join, Class<V> type) {
final Set<Join<X, ?>> joins = join.getParent().getJoins();
final Join<X, V> treatAs = ( (JoinImplementor) join ).treatAs( type );
joins.add( treatAs );
return treatAs;
}

Result query:

Hibernate 5.0.7.Final

select internalbl0_.*
from blrecord internalbl0_
inner join blentry entries1_ on internalbl0_.id=entries1_.record_id
where internalbl0_.dtype='1' and entries1_.dtype=$1 and entries1_.value=$2 and internalbl0_.status=$3
group by internalbl0_.id
having count(internalbl0_.id)=1

Hibernate 5.1.10.Final

select internalbl0_.*
from blrecord internalbl0_
inner join blentry entries1_ on internalbl0_.id=entries1_.record_id
inner join blentry entries2_ on internalbl0_.id=entries2_.record_id
where internalbl0_.dtype='1' and entries2_.dtype=$1 and entries2_.value=$2 and internalbl0_.status=$3
group by internalbl0_.id
having count(internalbl0_.id)=1

To make it works I need to add DISTINCT to "count(internalbl0_.id)" => "count(DISTINCT internalbl0_.id)".

Hibernate 5.2.12.Final

I've replaced 5.1.10 with 5.2.12 in WildFly 11 and got the same extra JOIN.

How should I use treat method? May be approach was changed...

Environment

None

Assignee

Unassigned

Reporter

Stanislav Grushevskiy

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Worked in

5.0.10

Components

Affects versions

Priority

Major
Configure