-->
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.  [ 3 posts ] 
Author Message
 Post subject: ¿Is it possible to map attributes to custom resolvers?
PostPosted: Tue Feb 16, 2010 1:59 pm 
Newbie

Joined: Tue Feb 16, 2010 1:57 pm
Posts: 4
Maybe it is the wrong place to make this question, and I know it has to be a really basic hibernate question, well, my problem is that I have a pojo like this one:

class Pojo {

Integer id;
TypeA foo;
TypeB zas;
... getters and setters....

}

class TypeA {

Integer id;
String description;
... getters and setters....

}


class TypeB {

Integer id;
String description;
... getters and setters....

}


and I have two mappings, for Pojo and TypeA, but not for TypeB


<hibernate-mapping >
<class name="Pojo"
table="pojo_table">

<id column="pojo_id" name="id" type="int"
unsaved-value="0">
<generator class="native" />
</id>

<property name="foo" class="TypeA" column="pojo_foo" />

<property name="zas" class="TypeB" column="pojo_zas" />

</class>

<class name="TypeA"
table="typea_table">

<id column="typea_id" name="id" type="int"
unsaved-value="0">
<generator class="native" />
</id>

<property name="description" class="string" column="description" />

</class>

</hibernate-mapping>

But as you can see there is no TypeB mapping, because this value is being set in the service layer by a web service query, but I just want to persist the id of the returned object (TypeB). thus I want something like to transform cell values for TypeB (the id) and the object itself. Is someway to register something like this with hibernate?


Maybe something like this
public class TypeBResolver{

public Integer getAsCellValue( TypeB foo) {
TypeB d = (TypeB)foo.getValue();
if (d == null) {
return null;
}
return d.getId();
}

public TypeB resolvCellValueForPojo(Integer s) {
if (s != null) {

return typeBService.getB(s);

} else {return null}

}


Top
 Profile  
 
 Post subject: Re: ¿Is it possible to map attributes to custom resolvers?
PostPosted: Tue Feb 16, 2010 3:33 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
It sounds like you need a custom user type. There is a short section about this in the Hibernate documentation: http://docs.jboss.org/hibernate/stable/ ... pes-custom

Read this and then google around a bit and you'll find some real code examples as well.


Top
 Profile  
 
 Post subject: Re: ¿Is it possible to map attributes to custom resolvers?
PostPosted: Tue Feb 16, 2010 4:44 pm 
Newbie

Joined: Tue Feb 16, 2010 1:57 pm
Posts: 4
Yes, you are right, after a couple of hours I found that... It is absolutely amazing that I can replace some not existing tables in the database with a UserType and retrieve data from a web service, for example. I found examples here, if someone else is interested.

http://i-proving.ca/space/Technologies/ ... +Hibernate


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