I have these simplified types:
public class DataBean extends ZZZZZ {
public String name;
}
public class Member extends CCCCC {
public DataBean m_data;
}
I’d like to map m_data.name directly within Member.
I cannot use any sort of inheritance between the two (occupied already!).
This would be ideal:
<property name="m_data.name" column="name" type="string" access="field" />
Any idea? Is it possible with Hibernate?
Currently I’m getting this error:
org.hibernate.PropertyNotFoundException: field [m_data.name] not found
on com.example.Member
The main reason is that I’m trying to (re)use a data bean taken from an http service, and I really don’t feel like rewriting all the fields, nor writing a setter/getter.
The
nameproperty is actually in theDataBeanclass. So, the exception you are getting is obvious. Because the mapping is forMember.The
DataBeanis embedded inMemberand to map the field in the embedded class you have to use the<component>element.Please refer to this answer to this question here in SO: Hibernate @embeddable annotation equivalent for XML mapping file?
The answer also has a link to the page that explains what embedded objects are how to map them.
Update: