File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Certification » JPA Certification (OCEJPA)
Bookmark "Problems With @ElementCollection" Watch "Problems With @ElementCollection" New topic
Forums: Object Relational Mapping JPA Certification (OCEJPA)

Problems With @ElementCollection

Maocai Wu

Joined: Dec 23, 2013
Posts: 2
Please Help!! I have the following lines in my Employee Entity:

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

Joined: Apr 07, 2010
Posts: 2099

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.

Maocai Wu

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

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


Jaikiran Pai

Joined: Jul 20, 2005
Posts: 10441

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 ( 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: 1341


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: )
major : 5
minor : 1

Hibernate version is 3.6.10

Oracle certified Java 8 Programmer I (1Z0-808), 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, CIW Certified Ecommerce specialist
I agree. Here's the link:
subject: Problems With @ElementCollection
It's not a secret anymore!