-->
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.  [ 3 posts ] 
Author Message
 Post subject: Converting join-table to Map<key,value>
PostPosted: Fri Feb 26, 2010 10:36 am 
Newbie

Joined: Fri Feb 26, 2010 10:19 am
Posts: 3
Hello,

I've got 2 types of databags in my Java-code. One represents a 'Class' (a bunch of students) and the other represents a 'Test' (something the students have to do). I want to link all the Tests they may do, to a particular Class. I want to use a collection (Map) for this.

I have therefore 3 tables in my database: 'classes' (with primary key 'class_id'), 'tests' (primary key is 'test_id') and an association/join-table 'classes_tests'. This table got two foreign keys 'class_id' and 'test_id' and a third column 'obligatory' that is set true when the test has to be performed.

I use annotations to map the database with the databags. I didn't had any problems until this point, but now I don't succeed to use a 'Map' (like HashMap) wich has a Test as key and the column obligatory as value.

This is the code I have so far for this Map:
Code:
    @CollectionOfElements
    @JoinTable(name = "classes_tests", joinColumns = @JoinColumn(name = "class_id"))
    @MapKey(columns={@Column(name="obligatory")})
    private Map<Test,String> tests;


Top
 Profile  
 
 Post subject: Re: Converting join-table to Map<key,value>
PostPosted: Sat Feb 27, 2010 7:34 am 
Newbie

Joined: Fri Feb 26, 2010 10:19 am
Posts: 3
I've tried some things and now it works. I had to use MapKeyManyToMany.

But now I get an error in Netbeans:

basic attributes can only be of the following types: java primitive types,wrapper of primitive types, String, java.math.bigInteger, java.math.BigDecimal, java,util.Date, java.util.Calendar, java.sql.Data, java.sql.TimeStamp, byte[], Byte[], char[], Character[], enums, or any Serializable type


Top
 Profile  
 
 Post subject: Re: Converting join-table to Map<key,value>
PostPosted: Mon Mar 01, 2010 10:00 am 
Newbie

Joined: Fri Feb 26, 2010 10:19 am
Posts: 3
Nobody has ever got this error?


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

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.