This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 177243 - Hibernate Map Collection
Summary: Hibernate Map Collection
Status: RESOLVED WONTFIX
Alias: None
Product: javaee
Classification: Unclassified
Component: Persistence (show other bugs)
Version: 6.x
Hardware: All All
: P3 normal (vote)
Assignee: Sergey Petrov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-11-19 14:48 UTC by kjordan2001
Modified: 2014-07-07 18:00 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description kjordan2001 2009-11-19 14:48:46 UTC
Trying to map a Map<String,String> using Hibernate annotations gives the message: "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.Date, java.sql.Time, java.sql.TimeStamp, byte[], Byte[], char[], Character[], enums, or any Serializable type."  If I replace it with HashMap, it works since that implements Serializable, but I've never seen an example of it use an actual implementation of Map.  I've got it annotated correctly with @CollectionOfElements and @MapKey, and even @JoinTable, but it doesn't seem to like just Map.
Comment 1 Sergey Petrov 2009-11-19 22:35:56 UTC
Is it valid declaration for attributes in your opinion?
Comment 2 Sergey Petrov 2009-11-20 03:29:50 UTC
in my opinion if spec say it should be primitive, serializable etc then warning/eror is valid as Map itself do not extend Serializable.
Comment 3 kjordan2001 2009-11-20 08:14:55 UTC
Except that Hibernate itself has no problem with it.  If I deploy my project and run it, Hibernate will even create the table for the Map collection if I tell it to.  It's just going to store a key and value pair as two columns in the database, it's not the actual map that's going to be stored.  So it should probably more likely pay attention to the generics arguments since in my case what will be written to the database is the String key and String value inside the map.

I suppose there's no problem with using HashMap in the declaration, but I've still seen nowhere else having to use an actual implementation of Map for just the variable declaration.
Comment 4 kjordan2001 2009-11-20 08:31:21 UTC
Also, looking at it, what's the difference between doing at @CollectionOfElements on a Set or a List versus a Map other than Map gets another column for the key?  Both will create a new JoinTable, so they're pretty much the same except for the MapKey.  Neither Set nor List implement Serializable as they're both Interfaces also, so why wouldn't they throw an error also?  I'm not forced to use an ArrayList or a HashSet there to get rid of something that's not an issue in the first place where Netbeans is the only thing that is actually complaining about it.
Comment 5 Sergey Petrov 2014-07-07 18:00:28 UTC
hard to reevaluate now, but I suppose it's persistence issue, and hibernate was used as jpa provider with persistence.xml may be, now it's possible to turn off either individual jpa hints or some group of hints which may not be applicable to provider you use in your project, it's hard to handle any special providers cases and individual jpa extensions.
If you are still interested and I'm wrong with my assumption, feel free to reopen the issue, it's nice to provide sample project also.