-->
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 do a hibernate join of two tables.
PostPosted: Thu Oct 21, 2010 5:16 am 
Newbie

Joined: Thu Oct 21, 2010 5:04 am
Posts: 2
Hi,
I am a newbie to Hibernate. Please help with below issue.
We have two tables SALES(Sale_id,Producer,Product_Type) and PRODUCT_TYPE(Code,Description)

In the SALES table, the product code is stored.
I would like to join the tables into one POJO class SALES which has (Sale_id,Producer,prod_Type,productTypeValue). Note - Code is a varchar.
How can I do this ?

I tried this:
<class name="com.sales.bo.SaleBO" table="SALES">
<id name="sale_Id" type="int">
<column name="SUBM_N"/>
<generator class="identity"/>
</id>
<property name="prodcuer" type="java.lang.String">
<column name="Producer"/>
</property>
<property name="prod_type" type="java.lang.String">
<column name="Product_Type"/>
</property>

<join table="PRODUCT_TYPE">
<key column="code"/>
<property name="productTypeValue" type="java.lang.String" >
<column name = "description" />
</property>
</join>
</class>


But got :
[SQLServer]Conversion failed when converting the varchar value 'AAR' to data type int.

Later I added the "property-ref" attribute inside the <key> tag.
But hibernate still queries on the primary key.
Is there a workaround for this problem ?


Top
 Profile  
 
 Post subject: Re: How to do a hibernate join of two tables.
PostPosted: Thu Oct 21, 2010 8:01 am 
Regular
Regular

Joined: Fri Aug 06, 2010 1:49 am
Posts: 102
Location: shynate26@gmail.com
What is ur exact requirement. Its not clear. Are you going to use the POJO for reporting ?

_________________

Cheers!
Shynate
mailto:shynate26@gmail.com
www.CSSCORP.com


Top
 Profile  
 
 Post subject: Re: How to do a hibernate join of two tables.
PostPosted: Thu Oct 21, 2010 10:36 pm 
Newbie

Joined: Thu Oct 21, 2010 5:04 am
Posts: 2
Hi yes I want to display it in the UI.

I found that this could be done using one-to-one as a workaround.
But when I save or update the object back can I ensure in some way that the reference table(PRODUCT_TYPE) does not get updated.


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.