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
|