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.