-->
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 join 2 tables without any primary key
PostPosted: Wed Jan 21, 2015 2:59 pm 
Newbie

Joined: Wed Jan 21, 2015 2:24 pm
Posts: 1
Hi,

I have 2 tables, here is the structrure.

@Table(name = "TXN")
public class Transaction implements Serializable {
private static final long serialVersionUID = 1L;

@Id
@Column(name = "TH_ID")
private Long iId;

@Column(name = "TH_CHARGE_MODEL_ID", unique = false, nullable = true, updatable = true, length = 40)
private Integer iChargeModelId;

@OneToMany(cascade = CascadeType.ALL,fetch=FetchType.EAGER)
@JoinColumn(name="chargeModelId")
private List<SoftDescriptorEntity> sdList;

}


@Entity
@Table(name = "SOFTDESCRIPTORS")
public class SoftDescriptorEntity implements Serializable {
private static final long serialVersionUID = 1L;

@Id
@Column(name = "SD_ID")
public Long id;

@Column(name = "SD_CHARGE_MODEL_ID", insertable = false, unique = false, nullable = false, updatable = false)
public Integer chargeModelId;

@Column(name = "SD_VALUE", insertable = false, unique = false, nullable = false, updatable = false)
public String value;

}


I want to fetch all the records from TXN table that match the chargeModelId from the SOFTDESCRIPTORS.

Thus I have used @JoinColumn(name="chargeModelId") in the Transaction class.

But when I run the application I am getting the following query when I am doing the criteria to select all the records from TXN table.

Select ...... from ...
where ....
left outer join
SOFT_DESCRIPTORS sdlist4_
on th1_.TH_ID=sdlist4_.SD_ID

This is not what I want. I want hibernate to compare TH_CHARGE_MODEL_ID and SD_CHARGE_MODEL_ID instead.


Kindly let me know if I am doing anything wrong in the @JoinColumn or anything I am missing.


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.