-->
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.  [ 16 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Execute hbm2doc with hbmtemplate
PostPosted: Mon Jan 12, 2009 8:59 am 
Newbie

Joined: Mon Sep 08, 2008 11:50 am
Posts: 12
Hi,

How I can execute the hbm2doc command with hbmtemplate command?

The examples in the documentation is only about generate java files.

I have this:

<hbmtemplate templatepath="templates" template="dot/entitygraph.dot.ftl" filepattern="{package-name}/{class-name}.html">
</hbmtemplate>

But I generate only this html files.

My modifications are for add the java types for fields in the diagram.

PD: Sorry if my english is not well... xP


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 15, 2009 8:23 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
hi,

<hbmdoc> also supports the template attribute so you can just use hbmdoc as is, but set the template attribute to where your templates are.

the reason hbmtemplate doesn't work well with hbm2doc templates is that the DocExporter contains parts of the logic for proper iteration.

Got an example of what your changes do ? something usable for others ?

p.s. sorry for not responding earlier, i by accident marked your question answered so I didn't spot it again before now..

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 15, 2009 9:12 am 
Newbie

Joined: Mon Sep 08, 2008 11:50 am
Posts: 12
max,

Thanks, I add the templates property in hbm2doc tag and work.

The changes I want to do is add the type of a property in the diagrams: class diagram and table diagram.

The properties appears like this:
<class diagram>
name: String

<table diagram>
name: varchar(20)

I add this in dot/entitygraph.dot.ftl (line 45):

${p.name}:${c2h.getHibernateTypeName(p)}\l

But doesn't work.

The exception is:

Caused by: freemarker.core.InvalidReferenceException: Expression c2h.getHibernateTypeName(p) is undefined on line 45, column 32 in dot/entitygraph.dot.ftl.

Any ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 15, 2009 10:33 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
rfuentesp wrote:

${p.name}:${c2h.getHibernateTypeName(p)}\l

But doesn't work.

The exception is:

Caused by: freemarker.core.InvalidReferenceException: Expression c2h.getHibernateTypeName(p) is undefined on line 45, column 32 in dot/entitygraph.dot.ftl.


hmm - that should just work. Maybe the method returns null for some specific property ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 15, 2009 3:31 pm 
Newbie

Joined: Mon Sep 08, 2008 11:50 am
Posts: 12
Any tip that check the property is valid?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 15, 2009 4:52 pm 
Newbie

Joined: Mon Sep 08, 2008 11:50 am
Posts: 12
I resolve the problem.

I put this:

<#assign lastIndexDot = p.type.returnedClass?last_index_of(".")>
${p.name}: ${p.type.returnedClass?substring(lastIndexDot + 1, p.type.returnedClass?length)}\l

And work :-)

By the way, I have a others freemarker files that work for the community.

For example:

In the PojoFields.ftl I add this:

<#foreach property in pojo.getAllPropertiesIterator()>
<#assign property_name_in_upper = "${property.name}"?upper_case>
public static final String ${property_name_in_upper} = "${property.name}";
</#foreach>

This create constants with the real names of the properties, very useful in the criteria queries, because the programer doesn't wrong type the name of the property.

Other is the generation of the toMap and fromMap methods:

toMap:

/**
* toMap
* @return Map
*/
public ${pojo.importType("java.util.Map")}<#if jdk5><String, Object></#if> toMap() {
Map<#if jdk5><String, Object></#if> map;
<#if pojo.isSubclass()>
map = super.toMap();
<#else>
map = new ${pojo.importType("java.util.HashMap")}<#if jdk5><String, Object></#if>();
</#if>
<#foreach property in pojo.getAllPropertiesIterator()>
<#assign property_name_in_upper = "${property.name}"?upper_case>
map.put(${property_name_in_upper}, ${pojo.getGetterSignature(property)}());
</#foreach>

return map;
}

fromMap:

/**
* fromMap
*/

public void fromMap(Map<#if jdk5><String, Object></#if> map) {
<#if pojo.isSubclass()>
super.fromMap(map);
</#if>
<#foreach property in pojo.getAllPropertiesIterator()>
<#assign property_name_in_upper = "${property.name}"?upper_case>
<#assign property_name_cap_first = "${property.name}"?cap_first>
set${pojo.getPropertyName(property)}((${pojo.getJavaTypeName(property, jdk5)}) map.get(${property_name_in_upper}));
</#foreach>

}

How I can contribute with this code?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 15, 2009 5:19 pm 
Newbie

Joined: Mon Sep 08, 2008 11:50 am
Posts: 12
I start now with the tablegraph.dot.ftl.

I put this in line 45:
<${p.name}>${p.name}: ${p.sqlType}\l

But I get an exception:

Caused by: freemarker.core.InvalidReferenceException: Expression p.sqlType is undefined on line 45, column 44 in dot/tablegraph.dot.ftl.
at freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:124)
at freemarker.core.Expression.getStringValue(Expression.java:118)

I think the variable p is a org.hibernate.mapping.Column and this class has a sqlType property.

Any ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 19, 2009 6:11 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
rfuentesp wrote:
I resolve the problem.

I put this:

<#assign lastIndexDot = p.type.returnedClass?last_index_of(".")>
${p.name}: ${p.type.returnedClass?substring(lastIndexDot + 1, p.type.returnedClass?length)}\l

And work :-)


sure, but it's a hack ;)
weird that the "real' method didn't work.

Quote:
By the way, I have a others freemarker files that work for the community.

For example:

In the PojoFields.ftl I add this:

<#foreach property in pojo.getAllPropertiesIterator()>
<#assign property_name_in_upper = "${property.name}"?upper_case>
public static final String ${property_name_in_upper} = "${property.name}";
</#foreach>

This create constants with the real names of the properties, very useful in the criteria queries, because the programer doesn't wrong type the name of the property.


there is a feature request in jira for this - but the way to generate this should be into an interface which users can then either say the entities implement or just refer to. Then i'll accept it into the codebase ;)

Quote:
Other is the generation of the toMap and fromMap methods:

toMap:

/**
* toMap
* @return Map
*/
public ${pojo.importType("java.util.Map")}<#if jdk5><String, Object></#if> toMap() {
Map<#if jdk5><String, Object></#if> map;
<#if pojo.isSubclass()>
map = super.toMap();
<#else>
map = new ${pojo.importType("java.util.HashMap")}<#if jdk5><String, Object></#if>();
</#if>
<#foreach property in pojo.getAllPropertiesIterator()>
<#assign property_name_in_upper = "${property.name}"?upper_case>
map.put(${property_name_in_upper}, ${pojo.getGetterSignature(property)}());
</#foreach>

return map;
}

fromMap:

/**
* fromMap
*/

public void fromMap(Map<#if jdk5><String, Object></#if> map) {
<#if pojo.isSubclass()>
super.fromMap(map);
</#if>
<#foreach property in pojo.getAllPropertiesIterator()>
<#assign property_name_in_upper = "${property.name}"?upper_case>
<#assign property_name_cap_first = "${property.name}"?cap_first>
set${pojo.getPropertyName(property)}((${pojo.getJavaTypeName(property, jdk5)}) map.get(${property_name_in_upper}));
</#foreach>

}

How I can contribute with this code?


about to/fromMap - isn't this better done with Hibernate's EntityMode.MAP ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 19, 2009 6:14 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
forgot to answer your question about how to contribute:

Create patch and attach it to existing or new jira discussing the feature.
If the patch includes tests it has a much higher chance being integrated.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 19, 2009 1:58 pm 
Newbie

Joined: Mon Sep 08, 2008 11:50 am
Posts: 12
rfuentesp wrote:
I start now with the tablegraph.dot.ftl.

I put this in line 45:
<${p.name}>${p.name}: ${p.sqlType}\l

But I get an exception:

Caused by: freemarker.core.InvalidReferenceException: Expression p.sqlType is undefined on line 45, column 44 in dot/tablegraph.dot.ftl.
at freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:124)
at freemarker.core.Expression.getStringValue(Expression.java:118)

I think the variable p is a org.hibernate.mapping.Column and this class has a sqlType property.

Any ideas?


And the answer about this? :-)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 19, 2009 3:36 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
my guess is that sqlType is not set - which would be true for reverse engineering since the sqlType is not used (currently).

if you use hbm.xml and set the sql-type you should see it.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2009 2:47 pm 
Newbie

Joined: Mon Sep 08, 2008 11:50 am
Posts: 12
I see in the doc/tables/table.ftl (line 257):
<strong>Type:</strong> ${dochelper.getSQLTypeName(column)}

How I use docHelper in the tablegraph.dot.ftl?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 21, 2009 8:10 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
it should just work ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 21, 2009 9:57 am 
Newbie

Joined: Mon Sep 08, 2008 11:50 am
Posts: 12
max wrote:
it should just work ?


No. The error is similar:

Caused by: freemarker.core.InvalidReferenceException: Expression dochelper is undefined on line 45, column 43 in dot/tablegraph.dot.ftl.
at freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:124)
at freemarker.core.TemplateObject.invalidTypeException(TemplateObject.java:134)

Any idea?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 21, 2009 10:26 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
what is the contents of that exact line ?

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