This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Problems in JPA with a Collection of Dates Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Problems in JPA with a Collection of Dates" Watch "Problems in JPA with a Collection of Dates" New topic
Author

Problems in JPA with a Collection of Dates

Stevie Braga
Greenhorn

Joined: Apr 04, 2006
Posts: 9
Hi!
I'm using JPA to do my O/R mapping, and I'm facing this problem: one User have a Set of quitting dates. So my mapping look like this:



But I keep getting this message when I try to run a test:


Can anyone tell me what I'm doing wrong?

Thanks

[ July 04, 2007: Message edited by: Stevie Braga ]
[ July 04, 2007: Message edited by: Stevie Braga ]

Stevie Braga
Ali Hussain
Ranch Hand

Joined: Jun 19, 2005
Posts: 211
Note sure but it seems to be a bug in hibernate release. A possible workaround could be: private Date[] quittingDates;

Let us know if you find some other solution.


- SCEA, SCJD, SCBCD, SCWCD, SCMAD, SCJP, ICAD (WebSphere), Lotus Principal CLP, Lotus CLP, Lotus CLS
Ali Hussain
Ranch Hand

Joined: Jun 19, 2005
Posts: 211
This would also work:



See this bug report and the workaround
Stevie Braga
Greenhorn

Joined: Apr 04, 2006
Posts: 9
I found out what I was doing wrong!

The @OneToMany annotation is use for relationships between entities, and I was trying to map a simple collection, not a collection of entities.
So I used the @CollectionOfElements annotation from hibernate, and it's working allright now! So now the code look like this:



Thanks for the attention Ali!
Ali Hussain
Ranch Hand

Joined: Jun 19, 2005
Posts: 211
Are you sure you want to use a hibernate annotation @CollectionOfElements in your code (I assume you want your code to be JPA compatible so you can change to any other implementation without changing the code)?
Erik Bengtson
Ranch Hand

Joined: Dec 06, 2003
Posts: 90
JPA does not support collections of dates. it only support collection of entities...

You need to wrap your date within an Entity (argh)...

FYI, JDO supports collections of any type.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problems in JPA with a Collection of Dates
 
Similar Threads
GWT + entities + JPA + DTO + Dozer
OpenEntityManagerInView, yet closed session
Berman and Braga must pay for their sins!
EJB 3, Entity question
Hibernate - Annotations - many to many association