is it possible to map attribute to custom resolvers?
by Jaime Hablutzel Egoavil
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:
<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.
public class TypeBResolver{
public Integer getAsCellValue() {
TypeB d = (TypeB) getValue();
if (d == null) {
return null;
}
return d.getId();
}
public TypeB resolvCellValueForPojo(Integer s) {
if (s != null) {
return typeBService.getB(s);
} else {return null}
}
--
Jaime Hablutzel
(tildes omitidas intencionalmente)
14 years, 9 months