-->
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.  [ 3 posts ] 
Author Message
 Post subject: "Operand should contain 2 column(s)" after HQL que
PostPosted: Thu Sep 29, 2005 10:17 am 
Newbie

Joined: Thu Sep 29, 2005 9:52 am
Posts: 4
Location: Germany
Hi all,
I am trying to load some data from our database and use the following HQL string: "FROM SeminarEventParticipant sep WHERE sep.user.id=?". The problem is, that I always get the error message "Operand should contains 2 column(s)".
I have to say that we use a special Id class which contains two values:

UID class:
- creation date (cd) - long value which contains the time in ms
- counter (c) - int value which contains a special counter

I searched in the forums and the net but I couldn't find a solution for my problem. Hopefully anybody of you knows a solution...

Here are my specs:

Hibernate version:
3.0.5

Mapping documents:
Code:
<class name="biz.solution4your.etutor.hibernate.seminar.SeminarEvent" table="seminar_event">
      <composite-id name="event" class="eTutor.beans.sql.UID">
         <key-property name="creationDate" column="event_cd"/>
         <key-property name="counter" column="event_c"/>
      </composite-id>
      <many-to-one name="seminar" not-null="true">
         <column name="seminar_cd"/>
         <column name="seminar_c"/>
      </many-to-one>
      <property name="start" column="start"/>
      <property name="end" column="end"/>
      <property name="address" column="address"/>
      <property name="location" column="location"/>
      <property name="description" column="description"/>
      <many-to-one name="user" not-null="true">
         <column name="user_cd"/>
         <column name="user_c"/>
      </many-to-one>
      <property name="maxParticipants" column="max_participants"/>
      <property name="minParticipants" column="min_participants"/>
      <property name="language" column="language"/>
      <bag name="seminarEventParticipant" table="seminar_event_participant">
         <key>
            <column name="event_cd"/>
            <column name="event_c"/>
         </key>
         <one-to-many class="biz.solution4your.etutor.hibernate.seminar.SeminarEventParticipant"/>
      </bag>
   </class>
   
   <class name="biz.solution4your.etutor.hibernate.seminar.SeminarEventParticipant" table="seminar_event_participant">
      <composite-id>
         <key-property name="assignment" type="biz.solution4your.etutor.dto.database.UidType">
            <column name="assignment_cd" />
            <column name="assignment_c" />
         </key-property>
         <key-many-to-one name="event">
            <column name="event_cd"/>
            <column name="event_c"/>
         </key-many-to-one>
         <key-many-to-one name="user" class="biz.solution4your.etutor.hibernate.User">
            <column name="user_cd"/>
            <column name="user_c"/>
         </key-many-to-one>
      </composite-id>
      <many-to-one name="seminar" not-null="true">
         <column name="seminar_cd"/>
         <column name="seminar_c"/>
      </many-to-one>
      <property name="insertDate" column="insert_date"/>
      <many-to-one name="coordinator" not-null="true">
         <column name="coordinator_cd"/>
         <column name="coordinator_c"/>
      </many-to-one>
      <property name="eventStatus" column="event_status"/>
      <property name="teachingMaterialReceived" column="teaching_material_received"/>
      <property name="reminderSent" column="reminder_sent"/>
      <property name="icalMethod" column="ical_method"/>
      <property name="icalPartstat" column="ical_partstat"/>
      <property name="icalUid" column="ical_uid"/>
      <property name="icalSequence" column="ical_sequence"/>
   </class>


Code between sessionFactory.openSession() and session.close():
Code:
        String hql = "FROM SeminarEventParticipant sep WHERE sep.user.id=?";
       
        Query q = dbSession.createQuery(hql);
        q.setParameter(0, user.getId());
       
        List<SeminarEvent> sel = q.list();


Full stack trace of any exception that occurs:
Code:
WARN  29 Sep 2005 15:46:09,244 org.hibernate.util.JDBCExceptionReporter  - SQL Error: 1241, SQLState: 21000
ERROR 29 Sep 2005 15:46:09,244 org.hibernate.util.JDBCExceptionReporter  - Operand should contain 2 column(s)
ERROR 29 Sep 2005 15:46:09,251 org.springframework.web.servlet.DispatcherServlet  - Could not complete request
org.hibernate.exception.GenericJDBCException: could not execute query


Name and version of the database you are using:
Code:
MySQL 4.1.8-Max


The generated SQL (show_sql=true):
Code:
Hibernate: select seminareve0_.assignment_cd as assignment1_, seminareve0_.assignment_c as assignment2_, seminareve0_.event_cd as event3_, seminareve0_.event_c as event4_, seminareve0_.user_cd as user5_, seminareve0_.user_c as user6_, seminareve0_.seminar_cd as seminar7_8_, seminareve0_.seminar_c as seminar8_8_, seminareve0_.insert_date as insert9_8_, seminareve0_.coordinator_cd as coordin10_8_, seminareve0_.coordinator_c as coordin11_8_, seminareve0_.event_status as event12_8_, seminareve0_.teaching_material_received as teaching13_8_, seminareve0_.reminder_sent as reminder14_8_, seminareve0_.ical_method as ical15_8_, seminareve0_.ical_partstat as ical16_8_, seminareve0_.ical_uid as ical17_8_, seminareve0_.ical_sequence as ical18_8_ from seminar_event_participant seminareve0_ where (seminareve0_.user_cd, seminareve0_.user_c)=?


TIA Tim


Top
 Profile  
 
 Post subject: composite key
PostPosted: Thu Sep 29, 2005 11:02 am 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
It looks like "user" has composite key that consists from 2 fields.
In HQL 'id' is keyword that provides access to object key, in case of composite key based criteria parts of the key should be accessed as:

from ZZZ z WHERE z.id.nameOfPartOne = ? [ and z.id.nameOfPartX = ?]

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 29, 2005 11:20 am 
Newbie

Joined: Thu Sep 29, 2005 9:52 am
Posts: 4
Location: Germany
Thanks a lot. Now I got it working :-)!


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