• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problems With @ElementCollection

 
Maocai Wu
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please Help!! I have the following lines in my Employee Entity:

@ElementCollection
@Column(name="NICKNAME")
private Collection<String> nickNames;

I keep getting the persistenceException : Could not determine type for: java.util.Collection, for columns : [org.hibernate.mapping.Column(NICKNAME)].

I use field access strategy for all my other attributes within the same entity. (I used different relationships in this entity. Such as @ManyToOne, @OneToOne, and so on. They all work fine if the above fragment is omitted)

Any suggestion to make @ElementCollection works?

 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2345
90
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Maocai Wu,

Welcome to Coderanch!

As you didn't get any answer so far, let me add your post also to the Object Relational Mapping forum and see if you will get an answer.

Regards,
Frits
 
Maocai Wu
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Frits,

Thank you so much for your concern. I really appreciate it.

Thanks,
Maocai


 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's been a while since I have worked with JPA so I can't say for sure what's wrong with the code you posted. A quick google search suggests that this might be a bug in Hibernate (http://blog.m1key.me/2010/06/orghibernatemappingexception-could-not.html). Are you using Hibernate as your JPA provider? If yes, then the solution seems to be to upgrade to 3.5.3-Final or later.
 
Abhay Agarwal
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I ran your sample code as mentioned below. It worked fine. Please post your whole code and also as mentioned above, please do post your JPA provider name and version





Output is - I get 2 tables created successfully - Employee and Employee_Nicknames

I am using Hibernate as JPA provider and MySQL as database.

21:59:20,502 INFO SettingsFactory:126 - Database ->
name : MySQL
version : 5.5.28
major : 5
minor : 5
21:59:20,502 INFO SettingsFactory:132 - Driver ->
name : MySQL Connector Java
version : mysql-connector-java-5.1.28 ( Revision: alexander.soklakov@oracle.com-20131125092425-yvejy3xvci77ru3k )
major : 5
minor : 1


Hibernate version is 3.6.10
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic