-->
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: how to map two tables into one entity?
PostPosted: Wed Sep 07, 2011 11:51 am 
Newbie

Joined: Wed Sep 07, 2011 10:53 am
Posts: 1
Hello,
I have two tables.
Code:
________________
|     USER       |
|________________|        _______________
| user_id        |       |    LANGUAGE   |
| name           |       |_______________|
| fk_language_id |<----> | language_id   |
|________________|       | label         |
                         |_______________|


I want to mapping them to the single class:
Code:
public class User{
   private Integer id;
   private String name;
   private String language;
   ...
}

Is it possible to do this?
Hibernate version 3.6.7.
I have no acess to DB so I can't create views.

I tried this mapping:
Code:
<hibernate-mapping package="my.example.entity">
   <class name="User" table="USER"  >
      <id name="id" column="user_id">
         <generator class="native" />
      </id>
      <property name="name" column="name" />   
      <join  table="LANGUAGE" optional="true"  >
         <key column="language_id" foreign-key="fk_language_id" />
         <property name="language" column="label" />
      </join>
   </class>
</hibernate-mapping>


but it generates following sql:
Code:
select
   u.user_id as user1_6_,
   u.name as name6_,
   l.label as label7_
from
   USER u left outer join LANGUAGE l on u.user_id=l.language_id


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.