Hello all,
I'm having this problem for the past couple of days:
I have a USERS table and a REVIEWS table, where the connection between them is one-to-many (a user has many reviews), based on the column USER_ID, found in both tables (long). However, the USER_ID column is NOT the primary key for the REVIEWS table: I have a REVIEW_ID (string) as a primary key, and the USER_ID is a foreign key.
The problem is that when i get a User object from the db (MySQL), i get an error:
Code:
java.sql.SQLException: Invalid value for getLong() - '29ab8052-425f-417f-844a-635b1ef1a6a6'
whats the way around this??? I am attaching the two mapping files:
users.hbm.xmlCode:
<hibernate-mapping>
<class name="com.domain.user.User" table="USERS">
<id name="id" type="long" column="USER_ID">
<generator class="native" />
</id>
<property name="name">
<column name="USER_NAME" />
</property>
<set name="reviews" lazy="false" inverse="true" cascade="save-update">
<key column="USER_ID" not-null="true"/>
<one-to-many class="com.domain.review.Review"/>
</set>
<property name="email">
<column name="EMAIL" />
</property>
</class>
</hibernate-mapping>
reviews.hbm.xmlCode:
<hibernate-mapping>
<class name="com.domain.review.Review" table="REVIEWS">
<id name="reviewId" type="string" column="REVIEW_ID">
<generator class="assigned"/>
</id>
<many-to-one name="user" column="USER_ID" lazy="false" cascade="all" class="com.domain.user.User" not-null="true"/>
<many-to-one name="reviewed" column="REVIEWED_ID" lazy="false" cascade="all" class="com.domain.reviewed.Reviewed" not-null="true"/>
<property name="reviewText">
<column name="REVIEW_TEXT" />
</property>
</class>
</hibernate-mapping>
Thanks for the help, I truly appreciate it!