6

I have made a class with name of Movie with folowing 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 have used hibernate annotation and object is bean. but when I try to open my hibernate session with the following code...

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

I encounter a problem regarding could not map a Java.Util.Map class. Here is 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'm new to hibernate and don't know exactly what's happening... please help me!

Ehphan
  • 537
  • 3
  • 7
  • 19

5 Answers5

4

that's because you have to use some jpa2 implementation! this guy had the same problem

Community
  • 1
  • 1
AmirMV
  • 215
  • 1
  • 11
2

I also face the same problem.It is late but i think it will help others.use @MapKeyColumn.here is my simple code

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

Shouldn't properties just be a List<String> type?

It sounds like Hibernates confusion is the same as mine which is, why is Properies a Map instead of a list? What exactly are you trying to do there?

Spencer Ruport
  • 34,865
  • 12
  • 85
  • 147
  • well, i have a list of properties for any movie object such as AKA, Language, Location, Aspect Ratio and... that they can change from a object to another, meaning that one move could have all of them and another could have only 2 or 3! so I uses a map to solve this problem, cause I didn't wanna have a null field in Movie object, due to some problems with Lucine, and now I have map which contains property name as key and value as value! – Ehphan Dec 01 '10 at 13:47
0

Aah I see, its a . I dont think you can map a primitive unless you are using latest jar. https://forum.hibernate.org/viewtopic.php?t=955308. Check that link. Could you make a class called as Properties with key and value and then use it? I had a similar problem and I had to use that approach.

Jinesh Parekh
  • 2,131
  • 14
  • 18
-1

Do you have both getter and setter for Properties?

Jinesh Parekh
  • 2,131
  • 14
  • 18
  • Yes, Movie class is totally bean, meaning has setter and getter for all of objects and a default constructor. – Ehphan Dec 01 '10 at 13:38