Nikita Protsenko

Greenhorn
+ Follow
since May 03, 2010
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Nikita Protsenko

It seems like you are using JPA 2.0 in the compile time, but your appserver provides only JPA 1.0 in the runtime. Here is a couple of links that may give you a clue about the error:

http://opensource.atlassian.com/projects/hibernate/browse/HHH-4955
http://stackoverflow.com/questions/2511997/i-am-getting-an-error-with-a-onetomany-association-when-using-annotations-with-gi

The prospect looks gloomy, though.
Hello, Anand!

I've found that there was a bug in some versions of Hibernate that looks very similar to your problem.

Link to the JIRA page

Which version of Hibernate do you use? I am using 3.5.1-Final. Maybe it is a root of the problem?

Best regards,
Nikita Protsenko
The following works for me:



I am using Hibernate/JPA too. I've skipped the @Generated annotation, though.

Here is the test code:



...and the output:


Everything seems to be working. Hope that'll help you.
I assume that the following clause gets in the way: "updatable = false, insertable = false". I think it stops the Hibernate from writing these fields into the database.
To do this, you'll have to use sub-queries. If you connect your Products via the "name" column, then your query should look like that:



I would also consider redesigning a data structure to use one-to-many association to keep your "versions" on the "many" end. This way you can query them more efficiently - in fact, all you need is to order them on the "timestamp" column in descending order and fetch the first one.

Best regards,
Nikita Protsenko