-->
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.  [ 8 posts ] 
Author Message
 Post subject: Default values for not-null fields Help reuired
PostPosted: Wed Apr 21, 2004 7:45 am 
Regular
Regular

Joined: Tue Mar 23, 2004 2:10 am
Posts: 51
Hello,
I am using hibernate 2.1 and i got a problem. The scenerio is that i have a not null field in databse with default value.I am using Middle-Gen hibernate plugin to generate mapping files and then use hbm2java to generate my POJO (java bean). Alos i am using dynamic insert. Now to the real problem: i dont want to give value for taht field and wants that database inserts it automatically. But before passing the query to database hibernate give me error that i must specify a value for not-null column. Please help me asap as i am working on very important demo

Reggrads,
Shoaib Akhtar


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 21, 2004 7:53 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
just specify this field not-null = false as this constraint is managed by db.
Don't forget that is the db is updating the field (i suppose via a trigger), your hibernate session will contain stale data for the field...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 21, 2004 8:02 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Also specify insert="false", if you like.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 22, 2004 4:49 am 
Regular
Regular

Joined: Tue Mar 23, 2004 2:10 am
Posts: 51
Hello,
Thank for the answer Gavin. But i think that there should be some other way too as specifying not null false do not look elegant and insert = false will fail in the situation where one occasionaly wants to enter data in that field. There must be other way to do that.

>>Don't forget that is the db is updating the field (i suppose via a >>trigger), your hibernate session will contain stale data for the field...

I cannot unserstand what does this mean, is that hibernate will not contain data for this field after saving the record and i have to load this record again?????

Regards,
Shoaib Akhtar


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 24, 2004 4:43 am 
Regular
Regular

Joined: Tue Mar 23, 2004 2:10 am
Posts: 51
Hello,
One thing i want to ask hibernate developers.... it is possible to get generated values in jdbc3 then there should be some tags defined in hibernate mapping file to tell hibernate that after saving the record get value for those fields which are generated by database. I think it is possible by using getGeneratedKeys. Please take it as feature request as many legacy database systems exists that have a filed as not null defined and has default values for it and user may need them in next transaction immediately after saving the record and without retrieving it again.

Regards,
Shoaib Akhtar


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 24, 2004 10:04 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
getGeneratedKey only retrieves primary keys, not arbitary default values.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 25, 2004 7:11 am 
Regular
Regular

Joined: Tue Mar 23, 2004 2:10 am
Posts: 51
Hello,
Thanks for your quick response and my apology for not knowing it already. But i must say that there should be some way to acheive this (refer to prevoius conversation please), not know exactly how? one possible solution is that we may specify through some new hibernate tags that it loads the data ( for not null default fields) for those fields using select statement after it has insert data into database.I mean to say that insert into..... and afterwards select not_null_default_values_fields from ..... and put in the perisistant object.

Regards,
Shoaib Akhtar


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 25, 2004 7:22 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
session.flush();
session.refresh(object);


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