-->
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.  [ 7 posts ] 
Author Message
 Post subject: How complete extra columns?
PostPosted: Fri Jan 16, 2009 11:35 am 
Newbie

Joined: Fri Jan 16, 2009 11:20 am
Posts: 3
Hi, I have a question. I have a class 'X' and I want to it persist in table 'Y', but table 'Y' have a extra column that must have certain value. What do write in xml file?

Class 'X' Table 'Y'
private int a; -> column a;
private int b; -> column b;
column c; How indicate that this column must have, for
instance, the value 8?

Thanks and sorry my english.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 17, 2009 12:00 am 
Regular
Regular

Joined: Wed Oct 15, 2008 6:59 am
Posts: 103
Location: Chennai
use not-null="true" attribute in ur column tag in hibernate mapping file.

_________________
If u feel it will help you, don't forget to rate me....


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 17, 2009 5:27 am 
Newbie

Joined: Fri Jan 16, 2009 11:20 am
Posts: 3
But how indicate that the value is 8?

column = "columnC" not-null = "true" value="8 ???


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 17, 2009 6:35 am 
Regular
Regular

Joined: Wed Oct 15, 2008 6:59 am
Posts: 103
Location: Chennai
default="8"

_________________
If u feel it will help you, don't forget to rate me....


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 17, 2009 10:57 am 
Newbie

Joined: Fri Jan 16, 2009 11:20 am
Posts: 3
file.xml
...
...
<class name="classX"
table="tableY"
...
...
<property name="a" column="columnA" type="integer/>
<property name="b" column="columnC" type="integer/>

How and where write column="columnC" not-null="true" default="8"?
Remember that the class "X" hasnĀ“t attribute "c".

Very thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 17, 2009 11:11 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
You can't map a the 'columnC' in your hbm.xml file unless you also have a getter/setter for it in your 'X' class (*). I think the easiest way to solve this is at the database level. Eg. in your CREATE TABLE statement you should have something like:

Code:
CREATE TABLE X (
   ....
   columnC int NOT NULL DEFAULT 8,
   ....
)


* There are possibilities to overcome this by implementing a custom PropertyAccessor and specifying this in the 'access' attribute of the property definition for columnC.

Code:
<property name="c" column="columnC" type="integer"
   access="your.custom.PropertyAccessor" />


The use of a custom property accessor makes Hibernate call this instead of trying to call X.setC() and X.getC(). Check the Hibernate documentation for more info: http://www.hibernate.org/hib_docs/v3/re ... n-property and http://www.hibernate.org/hib_docs/v3/ap ... essor.html


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 17, 2009 12:29 pm 
Newbie

Joined: Thu Jan 15, 2009 3:55 pm
Posts: 12
Can you please trry it using:

Code:
<property name="a" column="columnA" type="integer" formula="8"/>

-thanks,
dip


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