-->
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: Help with an ¿easy? query
PostPosted: Wed Sep 22, 2010 5:18 am 
Newbie

Joined: Wed Jul 29, 2009 9:25 am
Posts: 9
Hello, how are you? I've been trying to solve this problem for hours and I am sure it must have an easy solution.

I have a many to many relation datasets <-> users, with the tables dataset_tb, user_dataset_tb and user_tb . Usually, I could do something like this to obtain the datasets for a certain user.

Code:
Dataset.hbm.xml
    <!-- Association many-to-many with zone_tb through product_zone_tb. -->
   <set name="users" table="user_dataset_tb" >
         <key column="dataset_id" />
         <many-to-many column="user_id" class="User" />
   </set>

java:
       Criteria crit = session.createCriteria(Dataset.class);
       crit.add( Restrictions.eq( "users.user_id", userId) ) );
       List result= crit.list();


But in this case, there is not user_tb table, and what I have is a dataset_tb and user_dataset_tb. Again, I would like to obtain the datasets for a certain user, but I cant get it to work. I tried this:

Code:
Dataset.hbm.xml
    <set name="userIds" table="user_dataset_tb" >
      <key column="dataset_id"/>
      <element column="user_id" type="long"/>
    </set>-->

java:
       Criteria crit = session.createCriteria(Dataset.class);
       crit.add( Restrictions.eq( "userIds", userId) ) );
       List result= crit.list();


With this configuration I can obtain the users for a dataset using Dataset.getUserIds, But I get this error when executing the opposite query:
Caused by: java.sql.SQLException: No value specified for parameter 1

I could create a stupe user_tb only with the user_id field and I would fix the problem, but there must be a better way. I really appreciate your help! thanks!


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.