-->
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.  [ 1 post ] 
Author Message
 Post subject: One-to-many mapping with column transformer
PostPosted: Tue Apr 09, 2013 3:11 am 
Newbie

Joined: Wed Mar 13, 2013 6:59 am
Posts: 3
Hello,
I have the following two DB tables:

Code:
CREATE TABLE nat_values(
  id Number NOT NULL,   
  speed Number(3,0),
  speed_ff Number(3,0),
  CONSTRAINT nat_values_id PRIMARY KEY (id)
)


CREATE TABLE area(
  id Number NOT NULL,
  id_nat_values Varchar2(15),
  area_c Number(4,0), 
  CONSTRAINT area_id PRIMARY KEY (id)
)



and the correspondent beans:

Code:
public class NatValues extends Entity{
   

   private Integer id;
   private Integer speed;
   private Integer speed_ff;
   private List<Area> areas;

   //constructor + get/set
}

public classArea extends Entity {

   private Integer id;
   private Integer nidC;
   
   //constructor + get/set
      
}



One object of nat_values can be related to many objects in area.
The field id in both tables is a number, but the field Area.id_nat_values, which relates an Area to one object of Nat_values is not nat_values.id, it is a coded string which can be obtained by calling the function DECODE(Area.id_nat_values).
I use a column transformer to achieve this, which works fine in a many-to-one mapping that I have for some other objects, but it is nt working in this.
This are my mapping files:

Code:
<hibernate-mapping package=".">
    <class name="NatValues" table="nat_values" lazy="false">
   <id name="id" column="id">
      <generator class="assigned"/>
   </id>
   <property name="speed" column="speed"/>
   <property name="speed_ff" column="speed_ff"/>

   <bag name="areas" table="AREA" cascade="all" fetch="select" lazy="false">
      <key>
         <column name="id_nat_values" write="encode_id('AREA', ?)"            read="decode_id(id_nat_values)"/>
      </key>
      <one-to-many class="Area" not-found="exception" />
   </bag>
</class>
</hibernate-mapping>


<hibernate-mapping package=".">
    <class name="Area" table="area" lazy="false">
   <id name="id" column="id">
      <generator class="assigned"/>
   </id>
   <property name="nidC" column="nid_c"/>
   </class>
</hibernate-mapping>


When I try to select the elements from nat_values Hibernate doesn't use the column transformers in the select, so it doesn't work and I can not get the list of areas.
any idea why is this happening?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.