-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: How to realize one-to-many mapping?
PostPosted: Tue Mar 23, 2010 4:02 am 
Newbie

Joined: Mon Feb 18, 2008 10:44 am
Posts: 10
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


Top
 Profile  
 
 Post subject: Re: How to realize one-to-many mapping?
PostPosted: Mon Oct 18, 2010 6:21 pm 
Newbie

Joined: Fri Sep 03, 2010 10:51 am
Posts: 4
Rod, did you find a solution to this issue?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.