Thursday, November 26, 2009

Hibernate annotation for a Map Enum type

Hibernate Annotations are so great, especially together with the Hibernate Tools that allows to generate the whole database (sql table definitions) from your annotated beans.
Right now I mapped the first time a java.util.Map with some enum type as key and a primitive type as value (java.lang.String).
The mapping looks like the following:

public class Test { 
    @JoinTable(name = "my_table") 
    @Cascade(value = org.hibernate.annotations.CascadeType.DELETE_ORPHAN) 
    @Enumerated(value = EnumType.STRING) 
    @org.hibernate.annotations.MapKey(columns = {@Column(name = "my_enum")}) 
    @Column(name = "my_value", length = 4000) 
    public Map getMappedValues() { 
        return _mappedValues; 

What I was not able to do was to define the type of the value (String) as hibernate type text. This gave the correct table/column definition at build time (hibernate tools), but a ClassCastException at runtime, saying that MyEnumType is not compatible to hibernate’s type text. So I used the length of the @Column annotation as a temporary workaround - I’ll dig into this now or later

1 comment:

  1. If you’d positioned your bets on any of these two zeros and the ball landed in your predicted quantity, you’d lose. Because of 카지노사이트 this, many confused folks had been learning to play actual money roulette, and the colours of these pockets had been modified to green in the 1800s. The top on-line roulette websites we suggest like to reward you by making certain have the ability to|you presumably can} play your favourite desk video games with a lovely bonus. Each of our really helpful roulette on-line websites offers an impressive welcome package deal that might put a smile on the face of any roulette fan.