java.lang.IllegalArgumentException: Unable to locate Attribute with the the given name [rdResponsesList] on this ManagedType [com.vw.asa.entities.Model]

I have a Mapped Super Class (Model) that is inherited by my entity RdResponses, where the attribute is being searched for.

In the source code, it appears that this line is called:

	PersistentAttributeDescriptor<? super J, ?> attribute = declaredAttributes.get( name );
		if ( attribute == null && getSuperType() != null ) {
			attribute = getSuperType().getAttribute( name );
		}
		checkNotNull( "Attribute ", attribute, name );

It seems that it just checks for existence of a super class, and then ‘assumes’ the attribute will be there? This kind of goes against the convention of mapped super classes.

When it calls getSuperType().getAttribute(name); it triggers the exception because that attribute is not in the MSC. Could there be a check done to see if the mapped super class contains that attribute? There are only a few attributes in my MSC that are inherited by a large number of entities.

Could you please show the model and how you try to lookup the attribute?

It’s an old post but I am having similar problems at the moment. I can tell you that you don’t have to declare attributes in the super class. It’s ok if they are declared in child class to be found. Because it works for the majority of my VOs where we declare attributes on child level.

Currently, I have similar problems where no attributes are found in my VO and declaredAttributes is empty in one case, while it works in many other cases. I suspect the mapping of my VO to play a role in all of this because, unlike my other VOs, the one causing the problems is mapped using composite-ids:

<?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>

Edit: I just tried to implement the approach where you define the keys that form the primary key in its own class:

public class UmsUserRoleId implements Serializable {

	private String userName; // These two attributes were in my VO before moving the key in its own class
	private String roleName;

	public UmsUserRoleId(String userName, String roleName) {
		this.userName = userName;
		this.roleName = roleName;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getRoleName() {
		return roleName;
	}

	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}

	public int hashCode() {
        ...
	}

	public boolean equals(Object o) {
        ...
	}
}

Then I added the key as an attribute to my VO:

public class UmsUserRoleVOImpl extends AbstractBasePropertiesImpl implements UmsUserRoleVO {

    private UmsUserRoleId id;

    public UmsUserRoleId getId() {
        return id;
    }

    public void setId(UmsUserRoleId id) {
        this.id = id;
    }
}

And now at least that key attribute is visible:

<?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.cl.ilogic.ums.common.business.UmsUserRoleVO">
        <composite-id name="id" class="com.myapp.ums.business.impl.UmsUserRoleId">
            <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>

And the intersting part is: when I modify my initial mapping like this:

<?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>
        <property name="userName" type="java.lang.String" />
        <property name="roleName" type="java.lang.String" />
    </class>
</hibernate-mapping>

Then the two attributes can be found.

Please create an issue in the issue tracker(https://hibernate.atlassian.net) with a test case(hibernate-test-case-templates/JPAUnitTestCase.java at main · hibernate/hibernate-test-case-templates · GitHub) that reproduces the issue.