-->
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: How to map rows from another table?
PostPosted: Mon Dec 17, 2012 7:14 am 
Newbie

Joined: Tue Sep 25, 2012 10:01 am
Posts: 4
Hello everyone. I'm quite new to Hibernate and need help in a hopefully simple task.

I do have: An XML mapping of table A to class A.java.

I do have: Another table B that has a common column with A (its value is key in A, but can occur more than once in B), and 2 other columns that I do need in the mapping to class A.

I can map a column region to a Set like this in the XML mapping of table A:

Code:
<set name="name of the Set" inverse="false" lazy="false" table="B" fetch="select">
   <key>
      <column name="the common column" not-null="true" />
   </key>
   <many-to-many entity-name="de.test.A">
      <column name="one of the 2 other columns in B" not-null="true" />
   </many-to-many>
</set>


... and do the same for the other column.

But, this does not help me since the order of a Set can be random, and if I get 2 Sets I can't know which values read from B's 2 other columns were in the same row. I do however need this information.

I too can't use mappings to List since B has no index column.

Does anyone know how I can work around my problem?

Thanks in advance and kind regards

Eques T.


Top
 Profile  
 
 Post subject: Re: How to map rows from another table?
PostPosted: Wed Dec 19, 2012 4:17 am 
Newbie

Joined: Tue Sep 25, 2012 10:01 am
Posts: 4
No one? Any one?


Top
 Profile  
 
 Post subject: Re: How to map rows from another table?
PostPosted: Wed Dec 19, 2012 6:52 am 
Newbie

Joined: Tue Sep 25, 2012 10:01 am
Posts: 4
Is it possible to use a query to solve this problem?

Code:
<hibernate-mapping>
   <class name="de.test.A" table="A">
      <id name="id" type="java.lang.Long">
         <column name="id" />
         <generator class="identity" />
      </id>
   </class>
   <query name="getColumn2AndColumn3OfTableB">

      I need something like the result of
      SELECT column_2, column_3 FROM B WHERE column_1 = theIdofA;
      This statement returns more than one row.

      Background: column_2 of B stores a long value; column_3
      stores a long value, or NULL

   </query>
</hibernate-mapping>


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.