This is with Hibernate 3.0.5
I have a pretty simple rating database. There are items to rate, users that rate items, and rating records:
Users: PK = Auto ID
Items: PK = Auto ID
Ratings: PK = Composite of two foreign keys (UserID, RatableItemID)
Here is the mapping hbm.xml:
Code:
<hibernate-mapping>
<class name="com.auenrec.data.Rating" table="Ratings">
<composite-id>
<key-many-to-one name="user" column="UserID"
class="com.auenrec.data.GenericUser"/>
<key-many-to-one name="item" column="RatableItemID"
class="com.auenrec.data.RatableItem"/>
</composite-id>
<property name="originalRating" column="OriginalRating" type="float"/>
<property name="normalizedRating" column="NormalizedRating" type="float"/>
<property name="ratingDate" column="RatingDate" type="timestamp"/>
<property name="enabled" column="Enabled" type="boolean"/>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="com.auenrec.data.GenericUser" table="GenericUsers">
<id name="id" column="ID">
<generator class="native"/>
</id>
</class>
</hibernate-mapping>
I want to query all Rating objects for a given user. I have tried:
Code:
from Rating WHERE user.id = ?
Code:
Hibernate: select rating0_.UserID as UserID, rating0_.RatableItemID as RatableI2_, rating0_.OriginalRating as Original3_5_, rating0_.NormalizedRating as Normaliz4_5_, rating0_.RatingDate as RatingDate5_, rating0_.Enabled as Enabled5_ from Ratings rating0_ where (rating0_.UserID, rating0_.RatableItemID)=? limit ?
SQL Error: 1241, SQLState: 21000
Operand should contain 2 column(s)
That SQL looks wrong. Why is it including RatableItemID in the WHERE clause?
I also have tried:
Code:
from Rating as ratung join rating.user as user WHERE user.id = ?
I get:
Code:
*** ERROR: Invalid path: 'rating.user'
*** ERROR: Invalid path: 'user.id'
*** ERROR: <AST>:0:0: unexpected end of subtree
I'm really lost as to what to do. I've done many searches and read through the docs and I can't figure out what I need to change. Please help!