Hello,
I'm trying to switch from XML configuration to annotation based configuration, but I'm stuck with a problem that I thought should not be that hard to solve, sadly I could not find anything about it that works.
I got a class named Event, the Event contains a Map<String,String> of the Events attributes. With the XML configuration this can be mapped easily:
Code:
<map access="field" name="attributes" table="eventattributes" lazy="false">
<key column="id"/>
<index column="key" length="1024" type="string"/>
<element column="value" length="4096" type="string"/>
</map>
My current approach with annotations is the following:
Code:
@ElementCollection(targetClass = String.class, fetch = FetchType.EAGER)
@MapKeyClass(String.class)
@AttributeOverrides({
@AttributeOverride(name="key", column=@Column(name = "key", length = 1024)),
@AttributeOverride(name="value", column=@Column(name = "value", length = 4096))
})
private Map<String,String> attributes = new TreeMap<String,String>();
Using this causes a exception I do not understand:
Code:
Caused by: org.hibernate.MappingException: Repeated column in mapping for collection: xxx.domain.EventDO.attributes column: count
at org.hibernate.mapping.Collection.checkColumnDuplication(Collection.java:341)
@CollectionOfElements worked, but it is deprecated, and I don't know how to adjust the column sizes.
Regards,
Sven