-->
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.  [ 3 posts ] 
Author Message
 Post subject: How to save object of child table Hibernate
PostPosted: Mon Jul 24, 2006 2:00 am 
Beginner
Beginner

Joined: Thu Jul 13, 2006 10:39 am
Posts: 23
Hi all,

I am very new to Hibernate.

I have two tables structure.

Dept:
-------------
dno number(2) primary key
dname varchar(20)

Emp:
---------------------
eno number(5) primary key
ename varchar(20)
dno number(2) foriegn key

---------------------------------------------

I have couple of quesions.

1. How will I insert a rcord into Emp table whose having
may-to-one relationship to dept table?

2. How will I select a particular emp details whose dno=10 using
session.createCriteria()?

Could anyone please to provide hbm files for these issues and sample
code.

please do favour with me

Thanks and Regards,
Sreekanth


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 24, 2006 3:00 am 
Newbie

Joined: Mon Jul 24, 2006 2:38 am
Posts: 1
I guess your pojos like this:
public class Dept{
private int dno;
private String dname;
private Set Emps;
public Dept( int dno, String dname, Set Emps){
......
}
/** set /get*/
}
public class Emp{
private int eno;
private String ename;
private Dept dept;
public Emp( int eno, String ename, Dept dept){
......
}
/** set /get*/
}
hibernate version 3.1 spring version 2.0
user spring's hibernate
1. Dept dept = new Dept();
dept.setDno(dno);
.....
dept.save(dept)

2. DetachedCriteria detachedCriteria = DetachedCriteria
.forClass(Emp.class);
detachedCriteria.createCriteria("demp").add(Expression.eq("dno",new Integer(10)));


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 24, 2006 3:09 am 
Beginner
Beginner

Joined: Thu Jul 13, 2006 10:39 am
Posts: 23
Than k u for ur favourable reply.....


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.