Hi all,
I have a very frustrating problem i cant get around. I have two table, USERS and REVIEWS. a User can have many reviews. The problem is, when i get a user, i get the following error:
Code:
java.sql.SQLException: Invalid value for getLong() - '29ab8052-425f-417f-844a-635b1ef1a6a6'
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
com.mysql.jdbc.ResultSetImpl.getLong(ResultSetImpl.java:2919)
com.mysql.jdbc.ResultSetImpl.getLong(ResultSetImpl.java:2830)
com.mysql.jdbc.ResultSetImpl.getLong(ResultSetImpl.java:2942)
org.hibernate.type.LongType.get(LongType.java:51)
...
Im thinking maybe this has to do with the fact that the USER_ID, which is the key for getting the relevant reviews from the REVIEWS table, is not the primary key for the REVIEWS table (it is REVIEW_ID, a varchar/ String). USER_ID is however defined as a FK, relating to the specific user.
I came across composite-key but was wondering if i need to add another primary key column only for the sake of this set. anyway, what is the right way to go about this?
i attach much of the relevant code/ mappings.
thanks a lot,
YoS.
this is the relevant part of the User class:
Code:
public class User implements Serializable
{
private long id;
private Set<Review> reviews; //map of reviews
private String email;
private String name;
//for hibernate
public User() {}
...
//getters, setters, etc.
the Review class:
Code:
public class Review
{
private long id;
private String reviewId;
private User user;
private Reviewed reviewed;
//for hibernate
public Review() {}
relevant parts of mapping classes:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<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>
Code:
<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.myguy.domain.user.User" not-null="true"/>
<many-to-one name="reviewed" column="REVIEWED_ID" lazy="false" cascade="all" class="com.myguy.domain.reviewed.Reviewed" not-null="true"/>
</class>
</hibernate-mapping>