aspose file tools*
The moose likes JPA Certification (OCEJPA) and the fly likes Problems With @ElementCollection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » JPA Certification (OCEJPA)
Bookmark "Problems With @ElementCollection" Watch "Problems With @ElementCollection" New topic
Forums: Object Relational Mapping JPA Certification (OCEJPA)
Author

Problems With @ElementCollection

Maocai Wu
Greenhorn

Joined: Dec 23, 2013
Posts: 2
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
Bartender

Joined: Apr 07, 2010
Posts: 1696
    
  25

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

Joined: Dec 23, 2013
Posts: 2
Hi Frits,

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

Thanks,
Maocai


Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10205
    
166

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.

[My Blog] [JavaRanch Journal]
Abhay Agarwal
Ranch Hand

Joined: Feb 29, 2008
Posts: 1162
    
    1

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

Oracle Java Web Service Developer (1z0-897), Oracle certified Java 7 Programmer, SCJA 1.0, SCJP 5.0, SCWCD 5.0, Oracle SQL Fundamentals I
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problems With @ElementCollection