-->
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: Setting a default property for a column in Hibernate
PostPosted: Thu Jun 30, 2005 10:42 am 
Beginner
Beginner

Joined: Thu Jun 23, 2005 11:23 am
Posts: 36
Location: Lancashire, England
Hallo -- is there a way to set a default value for a column in the mapping file?
I mean somthing like this:
Code:
<property name="isMain" type="boolean" not-null="true" default-value="false" />


but that would work!

Cheers,
doug.

_________________
Common sense is what tells you the world is flat.


Top
 Profile  
 
 Post subject: Re: Setting a default property for a column in Hibernate
PostPosted: Thu Jun 30, 2005 11:10 am 
Newbie

Joined: Thu Jun 30, 2005 10:49 am
Posts: 2
Hi

I think you need to use the <meta attribute> element to do this, instead of setting your mapping as:

<property name="isMain" type="boolean" not-null="true" default-value="false" />

Try setting it as:

<property name="isMain" type="boolean" not-null="true"><meta attribute="default-value">false</meta></property>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 01, 2005 10:02 am 
Beginner
Beginner

Joined: Thu Jun 23, 2005 11:23 am
Posts: 36
Location: Lancashire, England
Thanks alot for that, man!
doug.

_________________
Common sense is what tells you the world is flat.


Top
 Profile  
 
 Post subject: Meta tag
PostPosted: Wed Jul 06, 2005 10:02 am 
Newbie

Joined: Thu Jan 29, 2004 5:27 pm
Posts: 5
Where can I read up on the meta tag? I've never seen it before!

Raj


Top
 Profile  
 
 Post subject: Answered my own question
PostPosted: Wed Jul 06, 2005 10:10 am 
Newbie

Joined: Thu Jan 29, 2004 5:27 pm
Posts: 5
Looking at the DTD, it clearly states what the purpose of this tag is.

<!--
META element definition; used to assign meta-level attributes to a class
or property. Is currently used by codegenerator as a placeholder for
values that is not directly related to OR mappings.
-->
<!ELEMENT meta (#PCDATA)>
<!ATTLIST meta attribute CDATA #REQUIRED>
<!ATTLIST meta inherit (true|false) "true">


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 06, 2005 9:05 pm 
Beginner
Beginner

Joined: Wed Jul 06, 2005 8:18 pm
Posts: 23
I believe that tag is only used for schema generation. To specify default value, just set it in your object (I usually do this in the constructor):

class Foo ... {
String bar = "defaultValue";

}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 07, 2005 10:02 am 
Expert
Expert

Joined: Wed Apr 06, 2005 5:03 pm
Posts: 273
Location: Salt Lake City, Utah, USA
ctran wrote:
I believe that tag is only used for schema generation.


Did you mean POJO generation (hbm2java)? That's the only place I've seen it used.

But I sure would love it if there were a meta attribute like a previous poster suggested for specifying a default value in the database. But that's a topic for the Tools forum. I'm going to search around in JIRA to see if something like that is in the works, or has been rejected in the past.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 07, 2005 10:19 am 
Expert
Expert

Joined: Wed Apr 06, 2005 5:03 pm
Posts: 273
Location: Salt Lake City, Utah, USA
Actually, I forgot that SchemaExport isn't considered part of the Tools extensions, so this is the right forum. I searched JIRA and couldn't find anything related to default values for SchemaExport. Does anyone know why this isn't a feature? It seems logical to be able to generate columns with default values, so I'm not sure why this isn't part of SchemaExport. Is there something I'm missing??


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.