-->
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.  [ 18 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: How to create meta - tags in .hbm.xml files
PostPosted: Tue Apr 25, 2006 9:47 am 
Newbie

Joined: Thu Mar 30, 2006 4:53 am
Posts: 12
Hibernate version:3.1
Hibernate Tools version:3.1.0 beta5
Name and version of the database:Oracle 10g


Hi,

i want to set the default-value meta tag via reveng, so i think i need to set the defaultValue in the Column Object.
Is there an easy way to do that, or how can i program a workaround?


Michael


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 25, 2006 9:58 am 
Beginner
Beginner

Joined: Mon Mar 27, 2006 5:25 am
Posts: 39
Location: India Hyderabad
<meta attribute="field-description">
@hibernate.property
column="ATTRIBUTELENGTH"
length="8"
</meta>

---------------
dont forget to rate


Last edited by vinaykumar on Tue Apr 25, 2006 10:40 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 25, 2006 10:28 am 
Newbie

Joined: Thu Mar 30, 2006 4:53 am
Posts: 12
I don't understand, but I think this won't solve my problem.

My DB has defined a lot of default values.

Like
Code:
...
DUMMY VARCHAR2(20) DEFAULT 'Hello World' NOT NULL
...


Now i want to create Mapping-Files with these default

Code:
<hibernate-mapping>
  ...
    <property name="dummy" type="string">
      <meta attribute="default-value">Hello World</meta>
      <column name="DUMMY " length="20" not-null="true" />
    </property>
  ...
</hibernate-mapping>


And after that i want to create the POJO

Code:
private String dummy = "Hello World";



Thanx for help

Michael


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 27, 2006 1:37 am 
Newbie

Joined: Thu Mar 30, 2006 4:53 am
Posts: 12
Ok, i have created the META tag. I modified the JDBCMetaDataDialect, the JDBCReader and the columns.ftl.

So my JDBC Configuration includes the COLUMN-DEF, but how do i get it into the generated POJO, some ideas?

I tried one day to create the correct POJO, but no chance so long.


Thanx for ideas,

Michael


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 27, 2006 4:48 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you would need to call out $pojo.getMetaString("default-value")

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 27, 2006 5:27 am 
Newbie

Joined: Thu Mar 30, 2006 4:53 am
Posts: 12
$pojo.getMetaString("default-value") throws an exception - Methode does not exist. I tried $pojo.getMetaAsString("default-value", ""), but on the way from JDBCReader to the BasicPOJOClass the "default-value" value got lost.

The only MetaAttribute i still have in my POJOs ist "use-in-equals".


Michael


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 27, 2006 5:41 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
well you said you modified jdbcreader ? does it add the tag correctly ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 27, 2006 6:44 am 
Newbie

Joined: Thu Mar 30, 2006 4:53 am
Posts: 12
In JDBCReader.processBasicColumns() the column.setDefaultValue() is set. I get the COLUMN_DEF in the JDBCMetaDataDialect.getColumns().

I don't found anything where it is set to the POJOClass object, that is used by the $pojo.getMetaAsString() method.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 27, 2006 7:17 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
so you are setting it on the coluymn, then akso read it from the column.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 27, 2006 9:01 am 
Newbie

Joined: Thu Mar 30, 2006 4:53 am
Posts: 12
I changed the JDBCBinder, so that the PersistenceClass which is created include the MetaAttribute "default-value". Now it works fine!

I thought this is the better way, instead of using the column. Or what do you mean.


Thx Michael

P.S.: Is it planned, that this feature is included into the reveng tool? (i don't mean my dirty hack!!)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 27, 2006 10:07 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
well, i don't really see the benefit of including default column in the pojo's. default column in the mapping files maybe; but only as an option.

patches welcome.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Defaults
PostPosted: Mon May 01, 2006 12:10 pm 
Newbie

Joined: Tue Nov 15, 2005 12:25 pm
Posts: 15
I also interested in generation of default values.
Can you send me changes you made to get defaults working


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 01, 2006 12:19 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
guys could you please explain to me why defaults are cool to generate into the pojo's ?

Things I have against them:

1) they can change in the db
2) one property not always equal to one column

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 18, 2007 10:12 am 
Beginner
Beginner

Joined: Thu Aug 03, 2006 3:43 am
Posts: 45
well you are right max... but it's still a nice feature to have if you need it and can't go around it... (other than doing it by hand)

I am using hivernate tools 3.2.0-beta9a, and I modified it so that it adds the meta tags just like Smudo99 said ... more or less... I updated the template to the latest revision of the repository (I was using a custom template and it didn't add the tags to the hbm files). I also changed the default RevengStrategy class to include a method that would tell me if a certain type is to use default values from the database(if available).

There is only one small thing left to do: for example in the case of Date fields the default value is 'Now' so inside the pojo I get Date name = 'Now'; instead of Date name = new Date(); ... Is there any way to do this other than modifying the getFieldInitialization method ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 19, 2007 3:09 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
getFieldInitialization() is the right place for this.

You still did not answer my questions on why it is cool to initialize the values to default when that default value will not be the correct one. e.g. Now is a good example of a value that it will be wrong to initialize with since it won't be 'Now' in db sense, but 'Now' for the time it was instantiated.

_________________
Max
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 18 posts ]  Go to page 1, 2  Next

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.