-->
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.  [ 5 posts ] 
Author Message
 Post subject: How to set a field value to null?
PostPosted: Mon Nov 01, 2004 4:26 am 
Newbie

Joined: Wed Oct 20, 2004 8:57 am
Posts: 5
I am using JBoss3.2.6 with Hibernate 2.1.6.
Everything is OK,But when I want to set a field in my table to null, it fails to do so.
My code goes like:
Code:
Session session =HibernateContext.getSession("java:/hibernate/MySessionFactory");
   List list = null;
   try {
      list = session.find("from EseExperimentUser as eeu where eeu.UserId = ?",userId,Hibernate.INTEGER);
                Iterator iter = list.iterator();
      while(iter.hasNext()){
         MyObject = (MyObject)iter.next();
         MyObject.setFiled1(null); //Filed1 is a filed that allows null value
         session.update(MyObject);
               
      }
   } catch (HibernateException e) {
      e.printStackTrace();
   }


After running this program, there is no exception; However the field1 in DB is remains no change. Why?

Thanks for your help!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 01, 2004 6:15 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
maybe you missed begintransaction & commit

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject: That is not the reason.
PostPosted: Mon Nov 01, 2004 11:43 pm 
Newbie

Joined: Wed Oct 20, 2004 8:57 am
Posts: 5
Thanks for your help.
But that is not the reason.
If I set the value to an integer, it works well.
So why null-value not?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 02, 2004 4:20 am 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
you have "beginTransaction" and "commit" in your code, or not?
If not, trust anthony, and try it with "bT" and "commit" ... i would say without that, it's "luck" if you will see changes in your db ... ;)

gtx
curio


Top
 Profile  
 
 Post subject: Thanks
PostPosted: Tue Nov 02, 2004 10:28 am 
Newbie

Joined: Wed Oct 20, 2004 8:57 am
Posts: 5
Thanks!
I added "beginTransaction" and "commit" in my code, it worked well;-)


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