Java Hibernate Display Exception! (Failed to determine type for: java.util.Map)

I created a class called Movie with the following fields:

@Id @GeneratedValue private Long id; private String name; @ElementCollection(targetClass = String.class) private Map<String, String> properties; private Double rate; private Integer votersCount; private Date releaseDate; private Integer runtime; @ManyToMany @JoinTable(name = "movie_director") @IndexColumn(name = "directorIndex") private List<Person> directors; @ManyToMany @JoinTable(name = "movie_writer") @IndexColumn(name = "writerIndex") private List<Person> writers; @OneToMany @IndexColumn(name = "roleIndex") private List<MovieRole> movieRoles; @ManyToMany @JoinTable(name = "movie_genre") @IndexColumn(name = "genreIndex") private List<Genre> genres; 

as you can see i used hibernate annotation and bean object. but when I try to open a hibernate session with the following code ...

 session = HibernateSessionFactory.getSessionFactory().openSession(); 

I had a problem related to the inability to map the Java.Util.Map class. Here is the exception stack trace:

 org.hibernate.MappingException: Could not determine type for: java.util.Map, for columns: [org.hibernate.mapping.Column(properties)] at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:266) at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:253) at org.hibernate.mapping.Property.isValid(Property.java:185) at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:410) at org.hibernate.mapping.RootClass.validate(RootClass.java:192) at org.hibernate.cfg.Configuration.validate(Configuration.java:1099) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1284) at main.HibernateSessionFactory.getSessionFactory(HibernateSessionFactory.java:29) at main.MainClass.main(MainClass.java:26) 

I am new to sleep mode and do not know exactly what is happening ... please help me!

+6
java hibernate-mapping hibernate-annotations
source share
5 answers

because you need to use some jpa2 implementation! this guy had the same problem

+3
source share

Shouldn't I have properties of type List<String> ?

It seems like the embarrassment of Hibernates is the same as mine, why is β€œMap Right” instead of a list? What exactly are you trying to do there?

0
source share

And I see him a. I do not think that you can draw a primitive if you do not use the last jar. https://forum.hibernate.org/viewtopic.php?t=955308 . Check out this link. Can you create a class called "Properties" with a key and value, and then use it? I had a similar problem and had to use this approach.

0
source share

I am also facing the same problem. I'm late, but I think this will help others. use @ MapKeyColumn.here - my simple code

 @ElementCollection(targetClass=String.class) @MapKeyColumn(name="Employee_Position") private Map<String,String> position=new HashMap<String,String>(); 
0
source share

Do you have both getter and setter for properties?

-one
source share

All Articles