I have two table,like follows:
Code:
create table USERINFO
(
ID VARCHAR2(18) not null,
NAME VARCHAR2(20) not null
)
Code:
create table ROLEINFO
(
RID VARCHAR2(18) not null,
ID VARCHAR2(18) not null
)
one user may contains many roles,so I make following configure:
user.hbm.xml is follows:
Code:
<hibernate-mapping>
<class name="Test.UserModel" table="USERINFO" schema="Test">
<id name="id" column="id" type="java.lang.String">
<generator class="assigned"/>
</id>
<property name="uname" type="java.lang.String">
<column name="name" length="18" not-null="true" />
</property>
<set name="ROLEINFO">
<key column="id"/>
<one-to-many class="Test.RoleMode" />
</set>
</class>
</hibernate-mapping>
role.hbm.xml is follows:
Code:
<hibernate-mapping>
<class name="Test.RoleMode" table="ROLEINFO" schema="Test" dynamic-update="true" select-before-update="true">
<composite-id>
<key-property name="rid" column="rid" type="string" />
<key-property name="uid" column="id" type="string" />
</composite-id>
</class>
</hibernate-mapping>
UserModel.java is follows:
Code:
public class UserModel implements Serializable{
private String id;
private String uname;
private Set role;
public String getId(){
return id;
}
public void setId(String id){
this.id=id;
}
public String getUname(){
return uname;
}
public void setUname(String uname){
this.uname=uname;
}
public Set getRole(){
return role;
}
public void setRole(Set role){
this.role=role;
}
}
RoleMode.java is follows:
Code:
public class RoleModel implements Serializable{
private String rid;
private String uid;
public String getRid(){
return rid;
}
public void setRid(String rid){
this.rid=rid;
}
public String getUid(){
return uid;
}
public void setUid(String uid){
this.uid=uid;
}
}
when I run above code,it raise following error:
Code:
Fatal: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/config/application.xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1401)
If I get rid of following configure from user.hbm.xml,it can run well.
Code:
<set name="ROLEINFO">
<key column="id"/>
<one-to-many class="Test.RoleMode" />
</set>
I guess it may raise error by using one-to-many.But I don't know how to correct it! Anybody could tell how to correct above code?
Thanks in advance