-->
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.  [ 2 posts ] 
Author Message
 Post subject: cant get the JOIN to Work ..
PostPosted: Mon Dec 31, 2007 6:06 am 
Newbie

Joined: Wed Nov 28, 2007 9:36 am
Posts: 8
hi ,

i have two entities :
Survey , SurveyQuestions
that are mapped like this :


Code:
<hibernate-mapping>
    <class entity-name="com.mts.dblayer.entities.wf.Surveys" table="SURVEYS" schema="dbo" catalog="WorkFlow">
        <id name="keyNum" type="java.lang.Long">
            <column name="KEY_NUM" precision="18" scale="0" />
            <generator class="identity" />
        </id>
......
<set name="SurveyQuestions" inverse="true">
            <key>
                <column name="SURVEY_KEY_NUM" precision="18" scale="0" />
            </key>
            <one-to-many entity-name="com.mts.dblayer.entities.wf.SurveyQuestions" />
        </set>
        <set name="surveyCustomers" inverse="true">
            <key>
                <column name="SURVEY_KEY_NUM" precision="18" scale="0" />
            </key>
            <one-to-many entity-name="com.mts.dblayer.entities.wf.SurveyCustomer" />
        </set>
    </class>
</hibernate-mapping>


<hibernate-mapping>
    <class entity-name="com.mts.dblayer.entities.wf.SurveyQuestions" table="SURVEY_QUESTIONS" schema="dbo" catalog="WorkFlow">
        <id name="keyNum" type="java.lang.Long">
            <column name="KEY_NUM" precision="18" scale="0" />
            <generator class="identity" />
        </id>
......
<many-to-one name="surveys" entity-name="com.mts.dblayer.entities.wf.Surveys" fetch="select">
            <column name="SURVEY_KEY_NUM" precision="18" scale="0" />
        </many-to-one>
<set name="surveyAnswerses" inverse="true">
            <key>
                <column name="QUESTION_KEY_NUM" precision="18" scale="0" />
            </key>
            <one-to-many entity-name="com.mts.dblayer.entities.wf.SurveyAnswers" />
        </set>
    </class>
</hibernate-mapping>



the code in the JSP :

Code:
Surveys surv = new Surveys(systemUser);
                                                   SurveyQuestions sq = new SurveyQuestions(systemUser);

                                                   surveyDao.addCriterion(surveyDao.createCriterion(
                                                   SurveysDAO.KEY_NUM, Long.valueOf(tmp_survey_num)));
                                                   Map dd = new HashMap();
                                                   dd.put("SurveyQuestions", "SurveyQuestions");
                                                   surveyDao.beginTransaction();
                                                   
                                                   surveyDao.JoinFind(SurveysDAO._SURVEYS, dd,CriteriaSpecification.INNER_JOIN, false);

surv = (Surveys) surveyDao.getItem(surv);
                                                      
                                                      Set sqSet2 = surv.getSurveyQuestionses();
                                                      Iterator it = sqSet2.iterator();
                                                      while (it.hasNext()) {
                                                          SurveyQuestions sqB = (SurveyQuestions) it.next();
                                                          System.out.println(sqB.toString());
                                                      }
....


the HQL query that is created is :
select this_.KEY_NUM as KEY1_31_1_, this_.VERSION as VERSION31_1_, this_.SURVEY_NAME as SURVEY3_31_1_, this_.COMPANY_KEY_NUM as COMPANY4_31_1_, this_.LAST_SUBSYS_NAME as LAST5_31_1_, this_.CREATION_DATE as CREATION6_31_1_, this_.LAST_UPDATE_DATE as LAST7_31_1_, this_.LAST_USER_NAME as LAST8_31_1_, surveyques1_.KEY_NUM as KEY1_32_0_, surveyques1_.VERSION as VERSION32_0_, surveyques1_.SURVEY_KEY_NUM as SURVEY3_32_0_, surveyques1_.QUESTION_STRING as QUESTION4_32_0_, surveyques1_.COMPANY_KEY_NUM as COMPANY5_32_0_, surveyques1_.LAST_SUBSYS_NAME as LAST6_32_0_, surveyques1_.CREATION_DATE as CREATION7_32_0_, surveyques1_.LAST_UPDATE_DATE as LAST8_32_0_, surveyques1_.LAST_USER_NAME as LAST9_32_0_ from WorkFlow.dbo.SURVEYS this_ inner join WorkFlow.dbo.SURVEY_QUESTIONS surveyques1_ on this_.KEY_NUM=surveyques1_.SURVEY_KEY_NUM where this_.COMPANY_KEY_NUM=? and this_.KEY_NUM=?

and it returns 5 rows .

i get an empty set of SuervyQuestion
and on the next line
:
Iterator it = sqSet2.iterator();
i get the error :

Code:
org.hibernate.LazyInitializationException: illegal access to loading collection
   at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:341)
   at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
   at org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:138)
   at org.apache.jsp.WF.Survey_jsp._jspService(Survey_jsp.java:265)
   at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
   at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
   at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
   at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
   at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
   at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
   at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)


please advise .


Top
 Profile  
 
 Post subject: another thing :
PostPosted: Tue Jan 01, 2008 11:30 am 
Newbie

Joined: Wed Nov 28, 2007 9:36 am
Posts: 8
HASHCODE() and EQUALS() addition to the pojo didn't help ...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.