-->
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.  [ 1 post ] 
Author Message
 Post subject: one-to-many mapping with primary key issue
PostPosted: Wed May 27, 2009 8:02 pm 
Newbie

Joined: Wed May 27, 2009 7:43 pm
Posts: 4
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>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.