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: Querying for many-to-many scenario
PostPosted: Fri Jan 20, 2006 2:24 pm 
Newbie

Joined: Fri Jan 20, 2006 1:59 pm
Posts: 1
Hello there,
I have been trying to query data for many-to-many without any success. Any help is hugely appreciated. Thanks a million in advance.

I want to find a list of all Questionnaires for the given Question.
========================================
Hibernate is generating this query :
2006-01-20 17:14:10,453 DEBUG: JDBCExceptionReporter:line63:logExceptions: could not execute query [select questionna0_.QuestionnaireId as Question1_, questionna0_.QuestionnaireName as Question2_5_
from VoteQuestionnaire questionna0_, VoteQuestion question2_, VoteQuestionLinks questions1_
where questionna0_.QuestionnaireId=questions1_.QuestionnaireId and questions1_.QuestionId=question2_.QuestionId and .=?]

And Postgres is coming back with this exception:

org.springframework.jdbc.BadSqlGrammarException: Bad SQL grammar [] in task 'Hibernate operation'; nested exception is org.postgresql.util.PSQLException: ERROR: syntax error at or near "."
org.postgresql.util.PSQLException: ERROR: syntax error at or near "."


========================================
String SQL = " From Questionnaire as questionnaireWhere questionnaire.Questions = ? ";
List fulllist = getHibernateTemplate().find(SQL, questions);


For reference, the object I used are :
=======================
public class Question implements Serializable {
private int myQuestionId = -1;
private String myQuestionName;
private Set myQuestionnaires;
// geters & setters removed
}

public class Questionnaire extends VotingBean {
private int myQuestionnaireId = -1;
private String myQuestionnaireName;
private java.util.Set myQuestions;
// geters & setters removed
}


Question.hbm.xml
===============

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping default-lazy="false">
<class name="com.digisoft.info.voting.model.bean.Question" table="VoteQuestion">

<id name="QuestionId" type="java.lang.Integer" column="QuestionId" unsaved-value="-1">
<generator class="sequence">
<param name="sequence">votequestion_questionid_seq</param>
</generator>
</id>

<property name="QuestionName" type="java.lang.String">
<column name="QuestionName" length="50" not-null="true" sql-type="varchar" unique="true" />
</property>

<set name="Questionnaires" table="VoteQuestionLinks">
<key column="QuestionId"/>
<many-to-many column="QuestionnaireId" class="com.digisoft.info.voting.model.bean.Questionnaire"/>
</set>
</class>
</hibernate-mapping>

Questionnaire.hbm.xml
===============

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping default-lazy="false">
<class name="com.digisoft.info.voting.model.bean.Questionnaire" table="VoteQuestionnaire">

<id name="QuestionnaireId" type="java.lang.Integer" column="QuestionnaireId" unsaved-value="-1">
<generator class="sequence">
<param name="sequence">votequestionnaire_questionnaireid_seq</param>
</generator>
</id>
<property name="QuestionnaireName" type="java.lang.String">
<column name="QuestionnaireName" length="50" not-null="true" sql-type="varchar" unique="true" />
</property>

<set name="Questions" table="VoteQuestionLinks">
<key column="QuestionnaireId"/>
<many-to-many column="QuestionId" class="com.digisoft.info.voting.model.bean.Question"/>
</set>
</class>
</hibernate-mapping>

This is basically having Set in HQL. I don't know how to ?
Thanks a million.

--Rana


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.