mysql - What are the hibernate annotations used to persist a Map with an enumerated type as a key? -
I'm having trouble getting the right hibernate annotation to use on map with an enumerated class here. And highly customized) are examples.
Public class talk {public string ID; Public letter launch operator; Public map & lt; Letter, double & gt; LetterCounts = New Hashmap & lt; Letter, double & gt; (); } Public Enumeration Letter {A, B, C, D}
Here are my current annotations
@Acti Public Speak talk {@Id public String id; @Enumerated (EnumType.STRING) public letter startLetter; @collectionOfElements @JoinTable (name = "Thing_letterFrequencies", joinColumn = @JoinColumn (name = "thingId") @MapKey (column = @column (name = "letter", nullable = false)) @ column (name = "count") Public Map & lt; Letters, Double & gt; LetterCounts = New Hashmap & lt; Letters, Double & gt; ();}
Hibernate to create tables for my MySQL database Generates the following DDL
Creating table thing (id varchar (255) not tap, startLetter varchar (255), primary key (id)) Type = InnoDB; Table Things_List Frequency (ChiefId varchar (255) do not make the taps, count the double precision, the letter Tinibob is not blank, the primary key (the chief ID, the letter) type = indodebi;
Note that the hibernate Trying to define a letter (my map key) as a small blockbock, though it defines the initiator as varchar (255), although both are of enumerated type letters when I make tables I see the following error:
Blob / Text column is used without 'letter' key specification
I googled this error And it appears that when you try to make a small block column part of the primary key, it is that there is a problem with MySQL, which needs to be straightened with the Thing_LeFrequencies table. So I have a copy of the letter for a varchar (255), the way it starts.
Unfortunately, I was confused with MapKey annotation for some time and it has not been able to work. I have tried @MapKeyManyToMany (targetEntity = Product.class) without success even if someone can tell me what is the right annotation for my letter. Map the map so that the letter can be treated in hibernation. The map key starts the same way as the way it starts? = "Text">
I found something that works on it Although it is ugly If you believe that the letter is in the com.myexample package then there are annotations
@collectionOfElements @JoinTable (Name = "Thing_letterFrequencies", joinColumn = @JoinColumn (name = "thingId")) @ MapKey (column = @column (name = "letter"), type = @ type (type = "org.hibernate.type.EnumType" , Parameter = {@Parameter (name = "enumClass", value = "com.myexample."), @Parameter (name = "type", value = "12"}})) @column (name = "count" ) Public maps & lt; Letter, double & gt; LetterCounts = New Hashmap & lt; Letter, double & gt; (); @Parameter (name = "type", value = "12") Note that the "value = 12" map is enumerated for a worker. Hope this helps someone else, but if there is a cleaner annotation without the use of magic numbers like 12, then I want to hear it.
Comments
Post a Comment