-->
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: Insert 'unsaved-value' property using reverse enginering
PostPosted: Wed Feb 09, 2011 7:23 pm 
Beginner
Beginner

Joined: Thu Mar 27, 2008 8:49 am
Posts: 27
I am using Reverse Engineering (reveng.xml file) in order to generate my hbm.xml files, but I need to set the 'unsaved-value' property for an id. Does anyone know how? It doesn't seem to be covered in the manual.

Maybe someone could also explain why I need the unsaved-value in my case? A Flex client sends a newly created domain object to the server. This domain object contains a Set of other domain objects. As I am using the Spring/Flex integration framework, the Flex object arrives at the server, and the Spring/Flex framework converts the Flex int (that is used for the primary key) into a Java Integer. As it is a Flex int, the resultant Java Integer has a value of 0, this is true of all the domain objects. I save the parent object, which works fine (even though it has an Integer value of 0, and does not use the unsaved-value parameter in the mapping file). However, when the cascade tries to save the domain objects in the Set, it fails with a Spring UnexpectedRollbackException. Hibernate runs an SQL insert statement for the parent, but then tries to run an update for the child objects (which as they haven't been saved yet, causes the exception). What is the likely cause of this behavior?


Top
 Profile  
 
 Post subject: Re: Insert 'unsaved-value' property using reverse enginering
PostPosted: Fri Feb 11, 2011 7:56 am 
Beginner
Beginner

Joined: Thu Mar 27, 2008 8:49 am
Posts: 27
I got around this by hacking the hibernate template.

In my ant script I added:

Code:
<hbm2hbmxml templatepath="${hibernate.auto.generator.custom.template.dir}">


and then in the ${hibernate.auto.generator.custom.template.dir} I copied the file hbm/id.hbm.xml from hibernate-tools.jar to ${hibernate.auto.generator.custom.template.dir}/hbm. I then hacked that file so that it always puts in the unsaved-value property, and everything works fine.

I notice that the file already contains:

Code:
<#if c2h.isUnsavedValue(property)>
        unsaved-value="${c2h.getUnsavedValue(property)}"
</#if>


so if anyone knows the correct way to trigger the c2h.isUnsavedValue(property) then I would be happy to find out how!


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.