-->
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.  [ 4 posts ] 
Author Message
 Post subject: How do I handle tables with columns with default values?
PostPosted: Fri Jul 07, 2006 9:14 am 
Regular
Regular

Joined: Wed Sep 28, 2005 6:45 pm
Posts: 56
I am using Hibernate with annotations.

I have table like this
Code:
CREATE TABLE etel.torderstatussnap
(
  orderstatussnapid int4 NOT NULL DEFAULT  nextval(('etel."torderstatussnap_id_seq"'::text)::regclass),
  orderstatussnap_orderid int4,
  orderstatussnap_statusid int4,
  orderstatussnapdate timestamptz DEFAULT now(),
  id_contact_handler int4
);


If I set the orderstatussnapdate column to insertable = false the default value, now() will be set in the database, but the data isn't read back into the object...

I want to use the databases now() since I am connecting to the database several places and not using hibernate on all those places either.

So, how should I handle this?

Surely somebody must have had the same problem?

Thanks in advance for any help!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 07, 2006 10:11 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
I don't know exactly the behaviour of this now. But maybe it's analogous to the trigger one.

Try the session.refresh() method on your object after saving it. It should be OK.

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 07, 2006 12:53 pm 
Regular
Regular

Joined: Wed Jan 11, 2006 12:49 pm
Posts: 64
Location: Campinas, Brazil
That default column generator works just like an 'identity' column, so I guess generator="identity" would work just fine.

_________________
Henrique Sousa
Don't forget to rate useful responses


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 07, 2006 7:44 pm 
Regular
Regular

Joined: Wed Sep 28, 2005 6:45 pm
Posts: 56
that looks like two helpful hints, I will look into both answers later. Thanks :)

session.refresh(object); did indeed refresh the object, just gotta call session.flush() first! ;)

It doesn't completely resolve the problem, but it helps :)

I am wondering if setting columns with default values to not insertable is a good option... It does atleast sound ok...

Now I am just wondering what I should do with situations where I only want to update some of the fields of a class... Probably I will have to use hql... A bit annoying to have to write 20 lines of code instead of one to update an object....

I could maybe have used dynamic updates, but then again, I would have to write hql for all those situations where I want to write a field with null to the database....

It would be close to optimal if I could turn on/off dynamic updates, but I think I would need to SessionFactory objects, which would be a complete mess :P


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