-->
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: ReverseEnginnering DB
PostPosted: Wed Sep 13, 2006 7:02 am 
Beginner
Beginner

Joined: Thu Nov 25, 2004 7:07 am
Posts: 43
Location: Germany
Hi all,

I use Hibernate Tool 3.2.0-beta7 and noticed that in my POJOs the column annotation sometimes contains a length attribute and sometimes not. The tables are all in the same Oracle schema and all are of type VARCHAR2.

Someone has an idea how I can achieve that the length attribute is always added to these columns? I want to automate my validation annotation generation process.

Thanks in advance,
Axel

_________________
You'll never get a second chance to make a first impression!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 13, 2006 7:27 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
the length is only included if it is not equal to the default length, e.g. Column.DEFAULT_LENGTH

if you want a different behavior then look at column.hbm.ftl

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 13, 2006 8:56 am 
Beginner
Beginner

Joined: Thu Nov 25, 2004 7:07 am
Posts: 43
Location: Germany
max wrote:
if you want a different behavior then look at column.hbm.ftl


I modified column.hbm.ftl. Now it looks like this.

Code:
<#if column.isFormula()>
<formula>${column.getFormula()}</formula>
<#else>
<column name="${column.quotedName}" ${c2h.columnAttributes(column)}>
<#if column.comment?exists>
<comment>${column.comment}</comment>
</#if>
</column>
<meta attribute="length">${column.length}</meta>
</#if>


It contains a meta-attribute length with the correct length. The XML file looks fine. I can see my meta attribute. e.g.

Code:
...
<property name="hitword" type="java.lang.String">
    <column name="HITWORD" not-null="true"></column>
    <meta attribute="length">255</meta>
</property>
...


But in my templates generating the annotated classes the meta attribute is not found resp. accessing it causes an exception.

Code:
...
${property.getMetaAttribute("length").getValue()}
...


Code:
Caused by: freemarker.core.InvalidReferenceException: Expression property.getMetaAttribute("length") is undefined on line 41, column 18 in pojo/PojoPropertyAccessors.ftl.


Can you give me a hint, why it's ignored here? I saw that the public method getMetaAttribute(String) exists in org.hibernate.mapping.Property! Are there only meta tags allowed mentioned in the doc as "Supported meta tags"? Formerly the meta tag length was valid (we used it). If it behaves like this, it would be impossible to store any information I want to use in my templates in a meta tag which I can compute in the templates. If the unknown meta tag will be ignored by other tools, this wouldn't matter.

Thanks,
Axel

_________________
You'll never get a second chance to make a first impression!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 13, 2006 5:29 pm 
Beginner
Beginner

Joined: Thu Nov 25, 2004 7:07 am
Posts: 43
Location: Germany
Is it possible to call the public methods from org.hibernate.mapping.Property within my templates?

_________________
You'll never get a second chance to make a first impression!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 14, 2006 2:02 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
The reason you are getting "undefined" is that the method returns null if there is no such meta attribute. Use c2j.getMetaAsString(property, "length", WhateverYouWantToBedefaultValue) to get a well defined result.

p.s. why are you putting in meta-attribute lengths here and not just adding it as the already existing attribute (e.g. only when it has the default value ?)

_________________
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.  [ 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.