-->
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.  [ 2 posts ] 
Author Message
 Post subject: Annotations strange behavior
PostPosted: Sat Mar 14, 2009 9:50 am 
Newbie

Joined: Sat Mar 14, 2009 8:59 am
Posts: 1
I have code similar to what is below. During runtime, when I do getVersions() it is returning it with the keys of the Map as Integer instead of a String. I can compile, but at Runtime get ClassCastException because I'm expecting a String value instead of Integer.

The only thing I can think of is there is a problem and something strange going on with @MapKey. The id is an Integer primary key of the Version class and that is how I want it related in the database. Using tools to read the annotations and create tables. But in my Java Map I want the key to be another String value of a field in the Version Class.


Code:

@Entity
public class Software {
    @OneToMany(mappedBy="software")
    @MapKey(name="id")
    public Map<String, Version> getVersions() {
        return versions;
    }
}



Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 14, 2009 12:28 pm 
Expert
Expert

Joined: Fri Jan 30, 2009 1:47 am
Posts: 292
Location: Bangalore, India
If you want some String field to be the key of the map then specify the name of that field inside the @MapKey instead of "id"

_________________
Regards,
Litty Preeth


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.