-->
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.  [ 2 posts ] 
Author Message
 Post subject: Generating DTOs with Hibernate Tools
PostPosted: Sat Mar 20, 2010 3:53 am 
Newbie

Joined: Sat Mar 20, 2010 1:54 am
Posts: 8
Hello,

I'm new to Hibernate, so forgive me if I'm overlooking something obvious.

I'm trying to use Hibernate & Hibernate Tools in a Java/BlazeDS/Flex application. I need to get around the lazy-loading/session context issue when passing objects to Flex via BlazeDS, and I'd like to keep the solution as simple as possible for now.

Using Hibernate.initialize() on the objects is causing StackOverflows like so:
[BlazeDS][ERROR] null
java.lang.StackOverflowError
at java.lang.ref.FinalReference.<init>(FinalReference.java:16)
at java.lang.ref.Finalizer.<init>(Finalizer.java:66)
at java.lang.ref.Finalizer.register(Finalizer.java:72)
at java.lang.Object.<init>(Object.java:20)

...and would be returning way too much data anyway.

It seems like generating some simple DTOs using Hibernate Tools, populating those from the VOs with Dozer, and sending them back would be a simple solution.

To generate DTO objects that only have the original properties of their entities (including foreign key ID fields), I'm guessing that I would need to create a custom Exporter class and possibly a custom POJOClass? As seen here:

http://anonsvn.jboss.org/repos/hibernat ... ool/hbm2x/
http://anonsvn.jboss.org/repos/hibernat ... bm2x/pojo/

Am I on the right track with this? I was trying to simply alter the default pojo's PojoFields.ftl, but pojo.getAllPropertiesIterator() returns the hash sets and object references that I'm trying to avoid. Am I correct that I would need to create a custom POJOClass with a data model built from the Hibernate libraries and use it in a custom exporter?

Also, any conceptual input on this out-of-session Hibernate object problem would be appreciated. I've searched around the forum and the web at large without finding a definitive answer. I'm also looking into Gilead as an option...


Top
 Profile  
 
 Post subject: Re: Generating DTOs with Hibernate Tools
PostPosted: Wed Mar 31, 2010 5:51 am 
Newbie

Joined: Sat Mar 20, 2010 1:54 am
Posts: 8
After some investigation it seems like I should be able to build DTOs by modifying the existing Pojo templates (rather than creating a custom Exporter class).

One-to-many relationship properties can be detected and excluded using field.getType().isEntityType() (true) and field.getType().isAssociationType() (true).

Many-to-one relationship properties can be detected and excluded using field.getType().isEntityType() (true) and field.getType().isAssociationType() (false).

However, I need to get the Java type and field name of the identifier property of the parent entities in the many-to-one relationship, so I can create the foreign identifier property on the DTO.

It seems like it should be possible to get a reference to the parent entity from the pojo field in the Freemarker template, but I so far I haven't found a way. This is the closest I've come:

Code:
<#-- // Fields -->
<#foreach field in pojo.getAllPropertiesIterator()>
   <#if field.getType().isAssociationType()>
      ${field.getValue()}
      <#foreach mappingColumn in field.getValue().getColumnIterator()>
         ${mappingColumn.getQuotedName()}
      </#foreach>
   </#if>
</#foreach>


field.getValue() returns org.hibernate.mapping.ManyToOne([org.hibernate.mapping.Column(ParentID)])

mappingColumn.getQuotedName() returns ParentID

I could hard code the Java type of the identifier and force the identifier column name to the proper case, but this is not an elegant solution.

I'll keep looking through the Hibernate docs and post here if I find a solution, but any hints would be appreciated.

Oh, and is the Hibernate Tools trunk (rev 18919) still only compatible with Hibernate 3.2? I've looked for the compatibility matrix but the majority of Google's links to the numeric JBoss reference pages are broken...


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