-->
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.  [ 5 posts ] 
Author Message
 Post subject: @Type for Maps from Element to Element
PostPosted: Thu Feb 07, 2008 5:15 am 
Newbie

Joined: Thu Feb 07, 2008 3:34 am
Posts: 3
Hi,

I'm trying to use a map from a user type to a string using the following Hibernate Annotations:

Code:
@CollectionOfElements
@org.hibernate.annotations.MapKey
@Type(type="personType")
private Map<String, PersonType> types = new HashMap<String, PersonType>();


Code:
@TypeDefs({
   @TypeDef(
      name="personType",
      typeClass=SimpleEnumUserType.class,
      parameters={
         @Parameter(
            name=EnumUserType.CLASS_NAME,
            value="package.pc.PersonType"
         )
      }
)


It seems that the @Type annotation applies to both the key and the value type, so Hibernate wants to persist the String as PersonType.

Code:
   
personEventDao.saveOrUpdate(personEvent);
personEvent.getTypes().put( "blabla",PersonType.MEMBER);
personEventDao.saveOrUpdate(personEvent);


The saveOrUpdate triggers a nullSafeSet in the EnumUserType for the String (as value) which fails, since it requires a PersonType.

The user type works in several other settings.


When swapping the Map types (and changing the test), the same error happens.

Code:
@CollectionOfElements
@org.hibernate.annotations.MapKey
@Type(type="personType")
private Map<PersonType, String> types = new HashMap<PersonType, String>();


But when both key and value are of the same type, everything works ok.

Code:
@CollectionOfElements
@org.hibernate.annotations.MapKey
@Type(type="personType")
private Map<PersonType, PersonType> types = new HashMap<PersonType, PersonType>();



I'm using Hibernate Annotations 3.3.0.ga and HSQLDB 1.8.0.7 + DBUnit 2.2 for testing.

The problem is in the context of a model driven software development (MDSD) project.

Is there a simple soultion to this problem? The knowledge of an absence of such a solution would also help me.

Thanks,
saturn


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 07, 2008 8:45 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I might have fixed this bug in 3.3.1, can you check JIRA. At least it reminds me something

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 08, 2008 2:52 am 
Newbie

Joined: Thu Feb 07, 2008 3:34 am
Posts: 3
I have seen nothing about this problem in the JIRA change log.

The topic http://forum.hibernate.org/viewtopic.php?t=967212 is about similar problem, but I have not found a JIRA issue directly concerning this.

I found a couple of unresolved JIRA issue that might be related to my problem:

This might be the JIRA you meant, altough I don't understand exactly what it means ("Support @Type annotated Annotation"):
http://opensource.atlassian.com/projects/hibernate/browse/ANN-461

A similar problem with @Enumerated:
http://opensource.atlassian.com/projects/hibernate/browse/ANN-657
It's forum entry:
http://forum.hibernate.org/viewtopic.php?p=2363187#2363187

This issue might solve the problem (@Type at class level):
http://opensource.atlassian.com/projects/hibernate/browse/ANN-58

I only checked the Hibernate Annotations part of the JIRA, since normal mapping files should work.

Thank you,
saturn


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 09, 2008 1:30 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
please open a new JIRA issue with a specific test case. I am not sure your pointers are related.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 11, 2008 4:57 am 
Newbie

Joined: Thu Feb 07, 2008 3:34 am
Posts: 3
JIRA issue is created:

http://opensource.atlassian.com/projects/hibernate/browse/ANN-696


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