File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problems in JPA with a Collection of Dates

 
Stevie Braga
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Ali Hussain
Ranch Hand
Posts: 211
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ali Hussain
Ranch Hand
Posts: 211
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This would also work:



See this bug report and the workaround
 
Stevie Braga
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 211
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 90
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic