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;
}
}