-->
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: Can I write criteria query joining view and a table
PostPosted: Thu Aug 01, 2013 4:28 am 
Newbie

Joined: Tue Jun 18, 2013 1:36 pm
Posts: 4
I have two table
1)application(application_id(pk),application_type,application_date,......,................,............)
2)application_survey(application_survey_id,application_id(fk),survey_no,resurvey_no,...............,..................,....................)

Here application_survey table includes multiple entries corresponding to application_id.

So I have created veiw

CREATE OR REPLACE VIEW v_application_survey AS
SELECT application_survey.application_id, string_agg(application_survey.survey_no::text,
CASE
WHEN btrim(application_survey.survey_no::text) = ''::text OR application_survey.survey_no IS NULL THEN ''::text
ELSE ','::text
END) AS survey_no, string_agg(application_survey.resurvey_no::text,
CASE
WHEN btrim(application_survey.resurvey_no::text) = ''::text OR application_survey.resurvey_no IS NULL THEN ''::text
ELSE ','::text
END) AS resurvey_no
FROM application_survey
GROUP BY application_survey.application_id;

ALTER TABLE v_application_survey OWNER TO postgres;



Then I need query

select* from application
left join v_application_survey on(v_application_survey.application_id=application.application_id),

using hibernate criteria query.Is it possible.If possible please reply with example.

Corresponding pojo class for v_application_survey is as follows

public class VApplicationSurvey implements java.io.Serializable {

private VApplicationSurveyId id;

public VApplicationSurvey() {
}

public VApplicationSurvey(VApplicationSurveyId id) {
this.id = id;
}

public VApplicationSurveyId getId() {
return this.id;
}

public void setId(VApplicationSurveyId id) {
this.id = id;
}

}

Corresponding mapping file for v_application_survey is as follows

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Aug 1, 2013 10:36:46 AM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="nic.mams.model.VApplicationSurvey" table="v_application_survey" schema="public">
<composite-id name="id" class="nic.mams.model.VApplicationSurveyId">
<key-property name="applicationId" type="java.lang.Long">
<column name="application_id" />
</key-property>
<key-property name="surveyNo" type="string">
<column name="survey_no" />
</key-property>
<key-property name="resurveyNo" type="string">
<column name="resurvey_no" />
</key-property>
</composite-id>
</class>
</hibernate-mapping>


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.