-->
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.  [ 1 post ] 
Author Message
 Post subject: Persisting Maps with UserType
PostPosted: Fri Jun 24, 2011 10:06 am 
Newbie

Joined: Tue Apr 05, 2011 9:37 am
Posts: 3
Hi,

I want to persist the following map:

Code:
  @javax.persistence.ElementCollection
  @javax.persistence.MapKeyColumn(name = "MyMapKey")
  @org.hibernate.annotations.Type(type = "MyUserType")
  public java.util.Map<java.lang.Integer, x.y.z.AnImmutableObjectClass> getTheMap()
  {
    return this.theMap;
  }

  public void setTheMap(java.util.Map<java.lang.Integer, x.y.z.AnImmutableObjectClass> value)
  {
    this.theMap = value;
  }


Unfortunately, the @Type-Annotation is used both for the Key and the Value of the map, so I have to do this (ugly) workaround (fix?) to avoid ClassCastExceptions on persisting:
Code:
  @javax.persistence.ElementCollection
  @javax.persistence.MapKeyColumn(name = "MyMapKey")
->  @org.hibernate.annotations.MapKeyType(value = @org.hibernate.annotations.Type(type = "org.hibernate.type.IntegerType")) <-
  @org.hibernate.annotations.Type(type = "MyUserType")
  public java.util.Map<java.lang.Integer, x.y.z.AnImmutableObjectClass> getTheMap()
  {
    return this.theMap;
  }

  public void setTheMap(java.util.Map<java.lang.Integer, x.y.z.AnImmutableObjectClass> value)
  {
    this.theMap = value;
  }


Is this the intended behaviour?
I found a bug in jira (marked as fixed) that the @Type-Annotation should only have an effect on the map value, not on the key. But that was back in 2008, Hibernate version 3.3.0 -> 3.3.1.
http://opensource.atlassian.com/project ... se/ANN-696

What is the current status on this? I found nothing in the specs/docs that stated clearly how it should work so I hoped to get something official here. :)

Thanks.


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

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.