[JIRA] (HHH-15553) Attributes not found for composite-key mappings: "java.lang.IllegalArgumentException: Unable to locate Attribute with the the given name"
by Patrick Lübbecke (JIRA)
Patrick Lübbecke ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=61a7428... ) *updated* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiZWUyM2RiMDY1... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-15553?atlOrigin=eyJpIjoiZWUyM2... ) HHH-15553 ( https://hibernate.atlassian.net/browse/HHH-15553?atlOrigin=eyJpIjoiZWUyM2... ) Attributes not found for composite-key mappings: "java.lang.IllegalArgumentException: Unable to locate Attribute with the the given name" ( https://hibernate.atlassian.net/browse/HHH-15553?atlOrigin=eyJpIjoiZWUyM2... )
Change By: Patrick Lübbecke ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=61a7428... )
We migrated +*Short summary:*+ it is not possible to fetch content from Hibernate mapping tables, that only have {{<composite-id>}} attributes.
I have 3 tables:
* User
* Role
* User_Role
We configure our entities using. 6 to 5 hbm. 6 xml files. The mapping file for User_Role has just a composite keys based on the IDs of User and I am currently migrating legacy Criteria API calls to JPA CriteriaBuilder Role. When I try to call fetching a tuple of the method root.gey(key) mapping table , I get this exception error in Hibernate 5.6.11 :
{{java.lang.IllegalArgumentException: Unable to locate Attribute with the the given name [userName] on this ManagedType [com.myapp.ums.business.impl.UmsUserRoleVOImpl]}}
The reason for this is that the attributes that are set as key-properties could not be found in {{AbstractManagedType#getAttribute(String name)}}:
!image-20220926-131848.png|width=1310,height=241!
Here is the code I use to prepare the DB queries:
{code:java}CriteriaBuilder cb = this.getSession().getCriteriaBuilder();
CriteriaQuery cq = cb.createQuery(aliasToBeanClass);
Root root = cq.from(aliasToBeanClass); // aliasToBeanClass is set to UmsUserRoleVOImpl
List<Predicate> predicates = new ArrayList<>();
predicates.add(cb.equal(root.get(key), value)); // key is set to "userName" - this line is causing the exception
{code}
*My mapping file*
{{<?xml version="1.0"?>}}
{{<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"}}
{{ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">}}
{{<hibernate-mapping>}}
{{ <class name="com.myapp.ums.business.impl.UmsUserRoleVOImpl" table="ums_t_user_role"}}
{{ proxy="com.myapp.ums.common.business.UmsUserRoleVO">}}
{{ <composite-id>}}
{{ <key-property name="userName" type="java.lang.String" column="fk_user_id"/>}}
{{ <key-property name="roleName" type="java.lang.String" column="fk_role_id"/>}}
{{ </composite-id>}}
{{ </class>}}
{{</hibernate-mapping>}}
*The interface:*
{code:java}public interface UmsUserRoleVO extends AbstractBaseProperties {
String ROLE_NAME = "roleName";
String USER_NAME = "userName";
String PROPERTIES = "properties";
String getUserName();
void setUserName(final String userName);
String getRoleName();
void setRoleName(final String roleName);
List<PmPropertyVO> getProperties();
void setProperties(List<PmPropertyVO> properties);
}{code}
*The entity:*
{code:java}package com.myapp.ums.business.impl;
public class UmsUserRoleVOImpl extends AbstractBasePropertiesImpl implements UmsUserRoleVO {
private static final long serialVersionUID = 6390635151578885216L;
private String roleName;
private String userName;
private List<PmPropertyVO> properties;
public UmsUserRoleVOImpl() {
}
@Override
public Long getRowguid() {
return super.getRowguid();
}
@Override
public void setRowguid(final Long rowguid) {
super.setRowguid(rowguid);
}
public String getRoleName() {
return roleName;
}
public void setRoleName(String roleName) {
this.roleName = roleName;
}
public List<PmPropertyVO> getProperties() {
return properties;
}
public void setProperties(List<PmPropertyVO> properties) {
this.properties = properties;
}
public boolean equals(Object o) {
...
}
public int hashCode() {
...
}
public String toString() {
return roleName + " " + userName;
}
@Get(UmsUserRoleVO.USER_NAME)
public String getUserName() {
return this.userName;
}
@Set(UmsUserRoleVO.USER_NAME)
public void setUserName(String userName) {
this.userName = userName;
}
}{code}
I think it has something to do with the mapping file not correctly processed.
( 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=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100207- sha1:ee9e30a )