-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: JPA nested composite PK
PostPosted: Mon Jan 27, 2014 10:34 am 
Newbie

Joined: Mon Jan 27, 2014 10:29 am
Posts: 1
Originally posted at http://stackoverflow.com/questions/21379405/jpa-nested-composite-pk

I'm trying to configure the JPA classes for the following PK requirements:

A Writer class / table with a PK of [Long id], for example [1], [2], [3]...

A Book class / table with a composite PK of [Writer Long id and Long index] (thus each writer has his own book indexes), for example [1, 1], [1, 2], [1, 3] (three books for writer #1), [2, 1], [2, 2], [2, 3], [2, 4] (four books for writer #2)...

A Page class / table with a composite PK of [Writer Long id, Book Long index and Long number] (thus each book has its own page numbers), for example [1, 1, 1], [1, 1, 2], [1, 1, 3], [1, 1, 4], [1, 1, 5] (five pages for writer #1 and his book index #1)...

What I need from a Book instance is to be able to call book.getWriter() and get a Writer instance; also, page.getBook() would return a Book instance. Of course, ALL three classes could easily have a simple Long PK and then, for example, a book would have the Writer as a not-nullable, @ManyToOne association outside the PK, but it doesn't suite our needs.

I've exhausted any configuration using @Embedded(|Id), @Embeddable, @IdClass, @MapsId, etc. I could think of or Googled, but Hibernate would always complain one way or the other, especially about the Page class where things are getting “nested”. Ideally, a later Paragraph class / table with a composite PK of [Writer Long id, Book Long index, Page Long number and Long paragraph index] should be configured likewise.

I hope someone has any good hints about this.

Thank you!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.