Patrick Lübbecke (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=61a7428...
) *updated* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiZTFlYTg0YzJj...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-15553?atlOrigin=eyJpIjoiZTFlYT...
) HHH-15553 (
https://hibernate.atlassian.net/browse/HHH-15553?atlOrigin=eyJpIjoiZTFlYT...
) Not possible to fetch content from mapping tables, that only have <composite-id>
attributes. (
https://hibernate.atlassian.net/browse/HHH-15553?atlOrigin=eyJpIjoiZTFlYT...
)
Change By: Patrick Lübbecke (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=61a7428...
)
*My mapping*
{noformat}<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class table="CompId" name="org.hibernate.bugs.CompIdVOImpl"
proxy="org.hibernate.bugs.CompIdVO">
<composite-id>
<key-property name="id1" column="id1" length="32"
type="string"/>
<key-property name="id2" column="id2" length="32"
type="string"/>
</composite-id>
</class>
</hibernate-mapping>
{noformat}
*The entity interface:*
{noformat}package org.hibernate.bugs;
public interface CompIdVO {
public String getId1();
public void setId1(String id1);
public String getId2();
public void setId2(String id2);
}{noformat}
*The entity implementation:*
{noformat}package org.hibernate.bugs;
import java.io.Serializable;
public class CompIdVOImpl implements CompIdVO, Serializable {
private String id1;
private String id2;
public CompIdVOImpl() {
}
public CompIdVOImpl(String id1, String id2) {
this.id1 = id1;
this.id2 = id2;
}
@Override
public String getId1() {
return id1;
}
@Override
public void setId1(String id1) {
this.id1 = id1;
}
@Override
public String getId2() {
return id2;
}
@Override
public void setId2(String id2) {
this.id2 = id2;
}
}{noformat}
The error:
{noformat} CriteriaBuilder cb = session.getCriteriaBuilder();
CriteriaQuery cq = cb.createQuery(CompIdVOImpl.class);
Root root = cq.from(CompIdVOImpl.class);
List<Predicate> predicates = new ArrayList<>();
predicates.add(cb.equal(root.get("id1"), "1"));
predicates.add(cb.equal(root.get("id2"), "2"));
cq.where(cb.and(predicates.toArray(new Predicate[0])));
Query query = session.createQuery(cq);
List<CompIdVO> entities = query.getResultList();{noformat}
Results in this error:
{noformat}java.lang.IllegalArgumentException: Unable to locate Attribute with the the
given name [id1] on this ManagedType [org.hibernate.bugs.CompIdVOImpl]
at
org.hibernate.metamodel.model.domain.internal.AbstractManagedType.checkNotNull(AbstractManagedType.java:148)
at
org.hibernate.metamodel.model.domain.internal.AbstractManagedType.getAttribute(AbstractManagedType.java:119)
at
org.hibernate.metamodel.model.domain.internal.AbstractManagedType.getAttribute(AbstractManagedType.java:44)
at
org.hibernate.query.criteria.internal.path.AbstractFromImpl.locateAttributeInternal(AbstractFromImpl.java:111)
at
org.hibernate.query.criteria.internal.path.AbstractPathImpl.locateAttribute(AbstractPathImpl.java:204)
at
org.hibernate.query.criteria.internal.path.AbstractPathImpl.get(AbstractPathImpl.java:177)
at
org.hibernate.bugs.CompositeIdTest.testImplicitCompositeIdInDynamicMapMode(CompositeIdTest.java:52){noformat}
That is pretty much a blocker for us. Christian Beikov mentioned that this problem [might
already be fixed in
6.0|https://stackoverflow.com/questions/73851482/java-lang-illegalargumen...].
I’d like to try to back port this fix to 5.6. Does anybody know which PR was relevant
here?
*Here is a test case for the problem:*
[^CompositeId (da4be8f3-7b63-42c2-85e3-f7dc6899b6f1).zip]
(
https://hibernate.atlassian.net/browse/HHH-15553#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-15553#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100209- sha1:392b984 )