-->
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: Setting default values for unmapped columns on insert
PostPosted: Fri Mar 09, 2007 7:33 am 
Newbie

Joined: Fri Mar 09, 2007 7:18 am
Posts: 2
I have no control over the database I am mapping to.

There are a number of columns that I do not care about in my object model and so don't want to map in my class.

But these columns need default values setting on insert (the default values are specific to my application, not set in the DB).


How do I can get NHibernate to populate these unused columns on insert, ignoring them forever after?


I assume I somehow need to use <sql-insert/> but I can't work out exactly how I'd do it.[/list]


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 10, 2007 8:15 am 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
I think you still need to map them if there are no defaults in the DB. You could map the fields to private members of your objects which are set with the default values and do the mappings as update = false.

Not sure if this helps, but there you go anyway.

Cheers,

Symon.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 11, 2007 12:22 pm 
Newbie

Joined: Fri Mar 09, 2007 7:18 am
Posts: 2
Thanks Symon. I was afraid I'd have to do that. Seems messy to pollute my domain model with fields that my app doesn't know about, but it could be worse.

Thanks for the reply.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 11, 2007 1:20 pm 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
To reduce the problem, I would advice you to define private field that you init with default values, but obviously without any public getter/setter. Maybe even accessing those fields with access method "field" would be a good idea?

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


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 16, 2007 4:02 pm 
Newbie

Joined: Sun Aug 28, 2005 10:54 pm
Posts: 14
merge_s.rottem wrote:
I think you still need to map them if there are no defaults in the DB. You could map the fields to private members of your objects which are set with the default values and do the mappings as update = false.


Furthermore, you may be able to clean-up your class declaration by representing these private fields in a component. I suppose this is a matter of preference since both solutions are equivalent.


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.