-->
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.  [ 11 posts ] 
Author Message
 Post subject: session.save(emp) problem
PostPosted: Tue Apr 11, 2006 6:16 am 
Beginner
Beginner

Joined: Mon Mar 27, 2006 5:25 am
Posts: 39
Location: India Hyderabad
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

[b]
I have a tabl ecalled EMP(eno,ename,salary)
In this i wanted to update the ename.
so i;ve done
Emp e = new Emp();
e.seteno(1);
e.setename("Vinay");
session.save(e);

if i execute above code wht ever the salary is there previously is updated to zero. So how can i update only ename in this
Kindly let me know


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 11, 2006 6:45 am 
Expert
Expert

Joined: Thu Sep 22, 2005 10:29 am
Posts: 285
Location: Almassera/Valencia/Spain/EU/Earth/Solar system/Milky Way/Local Group/Virgo Supercluster
Code:
Emp e = session.get(Emp.class, new Integer(1));
e.setEname("Vinay");
session.update(e);


Last edited by pepelnm on Tue Apr 11, 2006 6:50 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: use load
PostPosted: Tue Apr 11, 2006 6:49 am 
Newbie

Joined: Tue Apr 11, 2006 3:56 am
Posts: 3
first load emp

Emp e = session.load(Emp.class,new Integer(1));
e.setename("....");

then

session.flush();


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 11, 2006 6:58 am 
Expert
Expert

Joined: Thu Sep 22, 2005 10:29 am
Posts: 285
Location: Almassera/Valencia/Spain/EU/Earth/Solar system/Milky Way/Local Group/Virgo Supercluster
  • session.update is to "update" an existing entity
  • session.save is to "save" a new entity
  • session.saveOrUpdate to let Hibernate to choose save or update


Top
 Profile  
 
 Post subject: session.upate()
PostPosted: Tue Apr 11, 2006 8:41 am 
Beginner
Beginner

Joined: Mon Mar 27, 2006 5:25 am
Posts: 39
Location: India Hyderabad
I have a tabl ecalled EMP(eno,ename,salary)
In this i wanted to update the ename.
so i;ve done
Emp e = new Emp();
e.seteno(1);
e.setename("Vinay");
session.update(e);

if i execute above code wht ever the salary is there previously is updated to zero. So how can i update only ename in this
Kindly let me know


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 11, 2006 9:30 am 
Expert
Expert

Joined: Thu Sep 22, 2005 10:29 am
Posts: 285
Location: Almassera/Valencia/Spain/EU/Earth/Solar system/Milky Way/Local Group/Virgo Supercluster
Code:
Emp e = session.get(Emp.class, new Integer(1));
e.setEname("Vinay");
session.update(e);


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 11, 2006 9:34 am 
Beginner
Beginner

Joined: Mon Mar 27, 2006 5:25 am
Posts: 39
Location: India Hyderabad
Emp e = new Emp();
e.seteno(1);
e.setename("Vinay");
session.update(e);

if i do that the salary wil also updating.
i dont want to update the salary

regards
vinny


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 11, 2006 9:37 am 
Expert
Expert

Joined: Thu Sep 22, 2005 10:29 am
Posts: 285
Location: Almassera/Valencia/Spain/EU/Earth/Solar system/Milky Way/Local Group/Virgo Supercluster
Code:
Emp e = session.get(Emp.class, new Integer(1));

and not
Code:
Emp e = new Emp();


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 11, 2006 9:49 am 
Beginner
Beginner

Joined: Mon Mar 27, 2006 5:25 am
Posts: 39
Location: India Hyderabad
Hi Buddy,

anyway we are loading all the data into Emp
then we are updating.
againg it wil set all the data eno,sal and ename
can i restrict to only ename

regards
Samudrala Viany Kumar


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 11, 2006 9:57 am 
Expert
Expert

Joined: Thu Sep 22, 2005 10:29 am
Posts: 285
Location: Almassera/Valencia/Spain/EU/Earth/Solar system/Milky Way/Local Group/Virgo Supercluster
No, you can't as long as I know.

You can mark a property with update="false", but then it would be always readonly. I don't know if it is what you really want.

The other solution is to use a SQLQuery. But then, what do you want Hibernate for?.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 12, 2006 5:13 am 
Expert
Expert

Joined: Thu Sep 22, 2005 10:29 am
Posts: 285
Location: Almassera/Valencia/Spain/EU/Earth/Solar system/Milky Way/Local Group/Virgo Supercluster
look at 13.4. DML-style operations in the hibernate reference


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