Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hibernate mapping exception

 
raj baig
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
ref: to above:
can't i have java beans with the same name may be in different packages to map a same table:

like:


<class name="sas.login.User" table="myuser1">
<id name="user_id" column="user_id">
<generator class="assigned"/>
</id>
<property name="account_id" column="account_id"/>
<property name="uname" column="uname"/>
<property name="pwd" column="pwd"/>
</class>

<class name="sas.hibernate.User" table="myuser1">
<id name="user_id" column="user_id">
<generator class="assigned"/>
</id>
<property name="account_id" column="account_id"/>
<property name="uname" column="uname"/>
<property name="pwd" column="pwd"/>
</class>


when i use different java bean names there is no problem.
but when i use same javabean name in different packages also it throws Exception.
how to resolve it.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this is basically the same question that you are asking here. So I am going to close this duplicate post/thread. Please refrain from duplicate posting.

Thanks

Mark
 
raj baig
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
this is the error i am getting:

INFO - Mapping class: sas.login.User -> myuser1
DEBUG - Mapped property: user_id -> user_id
DEBUG - Mapped property: account_id -> account_id
DEBUG - Mapped property: uname -> uname
DEBUG - Mapped property: pwd -> pwd
error rg.hibernate.MappingException: Could not read mappings from resource: P
erson.hbm.xml


The code where i am accessing the hibernate is :

Configuration conf=new Configuration();
conf.configure();
SessionFactory sf=conf.buildSessionFactory();
Session session=sf.openSession();
Query qry1=session.createQuery("from sas.login.User where account_id=?");
System.out.println("query created");
qry1.setInteger(0,101);
List l1=qry1.list();
System.out.println("size: " +l1.size());
System.out.println("list created");
for(int i=0;i<l1.size();i++){
System.out.println("entered loop");
sas.login.User user1=(sas.login.User)l1.get(i);
System.out.println("user obj created");
System.out.println(user1.getUser_id());
System.out.println(user1.getAccount_id());
System.out.println(user1.getUname());
System.out.println(user1.getPwd());
}

Query qry2=session.createQuery("from saas.hibernate.User where account_id=?");
qry2.setInteger(0,102);
List l2=qry2.list();
System.out.println("size: " +l2.size());
for(int i=0;i<l2.size();i++){
saas.hibernate.User user2=(saas.hibernate.User)l2.get(i);
System.out.println(user2.getUname());
System.out.println(user2.getPwd());
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic