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!