Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Hibernate query using joins and like operator

Posted on 2013-12-19
1
Medium Priority
?
398 Views
Last Modified: 2013-12-19
I have two model classes:  

Class 1 looks like this:

@Entity
@Table(name = "Cdm_location_charge_class", catalog = "emscribedx")
public class Cdm_location_charge_class {
	private static Logger  LOG = Logger.getLogger(Cdm_location_charge_class.class);
	private int indx;
	private String location;
	private String charge_Class;
	private List <Cdm_trans> cdm_Trans;
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "indx")
	public int getIndx() {
		return indx;
	}
	public void setIndx(int indx) {
		this.indx = indx;
	}
	
	@Column(name = "location")
	public String getLocation() {
		return location;
	}
	public void setLocation(String location) {
		this.location = location;
	}
	@Column(name = "charge_Class")
	public String getCharge_Class() {
		return charge_Class;
	}
	public void setCharge_Class(String charge_Class) {
		this.charge_Class = charge_Class;
	}
	@OneToMany (mappedBy = "cdm_location_charge_class", targetEntity = Cdm_trans.class, cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	public List<Cdm_trans> getCdm_Trans() {
		return cdm_Trans;
	}
	public void setCdm_Trans(List<Cdm_trans> cdm_Trans) {
		this.cdm_Trans = cdm_Trans;
	}
}

Open in new window

--------------------------------------------------------------
And class 2 looks like this:



@Entity
@Table(name = "CDM_Trans", catalog = "emscribedx")
public class Cdm_trans {
	private static Logger LOG = Logger.getLogger(Cdm_trans.class);

	private int indx;
	private String charge_Class;
	private String charge_Code;
	private String charge_Description;
	private String charge_Eligibility;
	private String exp_Date;
	private BigDecimal rate_Charge;
	private String cpt_Code;
	private int rev_Code;
	private String charge_Type;
	private Cdm_location_charge_class locationchargeclass;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "indx")
	public int getIndx() {
		return indx;
	}

	public void setIndx(int indx) {
		this.indx = indx;
	}

	@Column(name = "charge_Class")
	public String getCharge_Class() {
		return charge_Class;
	}

	public void setCharge_Class(String charge_Class) {
		this.charge_Class = charge_Class;
	}

	@Column(name = "charge_Code")
	public String getCharge_Code() {
		return charge_Code;
	}

	public void setCharge_Code(String charge_Code) {
		this.charge_Code = charge_Code;
	}

	@Column(name = "charge_Description")
	public String getCharge_Description() {
		return charge_Description;
	}

	public void setCharge_Description(String charge_Description) {
		this.charge_Description = charge_Description;
	}

	@Column(name = "charge_Eligibility")
	public String getCharge_Eligibility() {
		return charge_Eligibility;
	}

	public void setCharge_Eligibility(String charge_Eligibility) {
		this.charge_Eligibility = charge_Eligibility;
	}

	@Column(name = "exp_Date")
	public String getExp_Date() {
		return exp_Date;
	}

	public void setExp_Date(String exp_Date) {
		this.exp_Date = exp_Date;
	}

	@Column(name = "rate_Charge")
	public BigDecimal getRate_Charge() {
		return rate_Charge;
	}

	public void setRate_Charge(BigDecimal rate_Charge) {
		this.rate_Charge = rate_Charge;
	}

	@Column(name = "cpt_Code")
	public String getCpt_Code() {
		return cpt_Code;
	}

	public void setCpt_Code(String cpt_Code) {
		this.cpt_Code = cpt_Code;
	}

	@Column(name = "rev_Code")
	public int getRev_Code() {
		return rev_Code;
	}

	public void setRev_Code(int rev_Code) {
		this.rev_Code = rev_Code;
	}

	@Column(name = "charge_Type")
	public String getCharge_Type() {
		return charge_Type;
	}

	public void setCharge_Type(String charge_Type) {
		this.charge_Type = charge_Type;
	}

	@ManyToOne
	@JoinColumn(name = "charge_Class", insertable = false, updatable = false)
	public Cdm_location_charge_class getLocationchargeclass() {
		return locationchargeclass;
	}

	public void setLocationchargeclass(
			Cdm_location_charge_class locationchargeclass) {
		this.locationchargeclass = locationchargeclass;
	}
}

Open in new window


-------------------------------------------------------------------------------------------------------------
The two classes correspond to two underlying tables:

Cdm_trans and Cdm_location_charge_class.    

I want to create a Hibernate Service that will give me the same result as the following sql query:

select cdm_trans.* from Cdm_trans, Cdm_location_charge_class where
cdm_location_charge_class.charge_Class = cdm_trans.charge_Class and
cdm_location_charge_class.location = <Some location passed to the method> and
Cdm_trans.charge_Description like '%<Some search term passed into the method>%;

My preference would be to do this using the Hibernate criteria API.   But I will go with HQL if that is the only way.     Can someone show me how to do this?

Thank you,
0
Comment
Question by:efamilant
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 60

Accepted Solution

by:
Kevin Cross earned 1500 total points
ID: 39729185
0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question