-->
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.  [ 5 posts ] 
Author Message
 Post subject: 2 tables in 1 entity
PostPosted: Tue May 02, 2006 10:28 am 
Newbie

Joined: Fri Apr 29, 2005 2:35 pm
Posts: 7
Hi,

Can I have 2 tables mapped in only 1 view? (it's like a view).


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 02, 2006 4:11 pm 
Newbie

Joined: Mon Apr 10, 2006 3:32 pm
Posts: 13
Do you mean something like this

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="de.laliluna.example">
  <class name="book" table="book">
    <composite-id>
       <key-property name="id" />
       <key-many-to-one name="customer" column="customer_fk" class="customer" />
    </composite-id>
    <property name="title" column="title" type="java.lang.String" />
    <property name="author" column="author" type="java.lang.String" />
    <property name="available" column="available"/>

  </class>
  <class name="customer" table="customer">       
    <id name="id">           
      <generator class="increment"/>       
    </id>               
    <bag name="books" inverse="false">       
      <key column="customer_fk" />       
      <one-to-many class="book"/>       
    </bag>
    <property name="name" column="name"/>       
    <property name="lastname" column="lastname"/>       
    <property name="age" column="age" />   
    </class>   
</hibernate-mapping>


In this mapping file i have two tables.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 03, 2006 8:02 am 
Newbie

Joined: Fri Apr 29, 2005 2:35 pm
Posts: 7
No,

I used to have a VIEW to represent a select between 2 tables
Example: Select t1.*, t2.* from table1 t1, table2 t2 where t1.cod = t2.cod

Ok, I don't have this view anymore and I want to map it. Is it possible?

Thank's at all.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 03, 2006 8:08 am 
Beginner
Beginner

Joined: Wed Jun 09, 2004 8:10 am
Posts: 28
http://www.hibernate.org/hib_docs/annot ... ml#d0e1583

Sorry I don't know how to map two tables using xml mapping. I use annotations.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 03, 2006 9:30 am 
Newbie

Joined: Wed Jan 26, 2005 11:01 am
Posts: 18
You can use a <join> to map a single entity to two tables, thus:

<class name="">
<id.../>
<property../>
...
<join table="">
<key column=""/>
<property.../>
</join>
</class>

The two tables will be joined by using the id column from the primary table and the key column from the secondary table. (don't use the property-ref, it does not work (yet...))


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