-->
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: Trying to use Annotations to define a Map of primitive types
PostPosted: Tue Feb 14, 2006 10:24 am 
Newbie

Joined: Tue Feb 14, 2006 10:07 am
Posts: 1
This code doesn't work:

Code:
@Entity
public class TestEntity implements Serializable
{
    private Integer id;

    @Id(generate = GeneratorType.NONE)
    public Integer getId()
    {
        return id;
    }

   // ...

    private Map<String, Integer> properties;

    @CollectionOfElements
    @Column(name="propValue", nullable = false)
    public Map<String, Integer> getProperties() {
        return properties;
    }
    public void setProperties(Map<String, Integer> properties) {
        this.properties = properties;
    }
}

*** Exception ***
org.hibernate.AnnotationException: A Map must declare a @MapKey element


Declaring a @MapKey doesn't work either:

Code:
@Entity
public class TestEntity implements Serializable
{
    private Integer id;

    @Id(generate = GeneratorType.NONE)
    public Integer getId()
    {
        return id;
    }

   // ...

    private Map<String, Integer> properties;

    @CollectionOfElements
    @MapKey(name="propName")
    @Column(name="propValue", nullable = false)
    public Map<String, Integer> getProperties() {
        return properties;
    }
    public void setProperties(Map<String, Integer> properties) {
        this.properties = properties;
    }
}

*** Exception ***
org.hibernate.AnnotationException: Associated class not found: java.lang.Integer


I'm trying to use Annotations to declare something like this:

Code:
      <map name="properties" table="properties">
          <key column="id"/>
          <index column="propName" type="string"/>
          <element column="propValue" type="string" not-null="true"/>
      </map>


The example above is based on "Hibernate in Action" section 6 pg 214. I thought this was a bug in Hibernate Annotations, but apparently it's not, since Emmanuel Bernard redirected me to the User Forum. Can anyone tell me what's wrong in the above example using Annotations?

Interesting enough, the same example using a Set works just fine:

Code:
@Entity
public class TestEntity implements Serializable
{
    private Integer id;

    @Id(generate = GeneratorType.NONE)
    public Integer getId()
    {
        return id;
    }

   // ...

    private Set<String> properties;

    @CollectionOfElements
    @Column(name="propValue", nullable = false)
    public Set<String> getProperties() {
        return properties;
    }
    public void setProperties(Set<String> properties) {
        this.properties = properties;
    }
}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 16, 2006 1:58 pm 
Newbie

Joined: Thu Feb 16, 2006 1:44 pm
Posts: 1
looks like same prob as this post

http://forum.hibernate.org/viewtopic.php?t=953403


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.