-->
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: Custom Field Serialization w/ JPA?
PostPosted: Thu Feb 18, 2010 9:38 pm 
Newbie

Joined: Thu Feb 18, 2010 9:06 pm
Posts: 1
I hope this is a fairly straightforward & newbie JPA question...

I'm trying to figure out how to map either an array of Objects or a List of Objects to an existing database schema.

For simplicity sakes, assuming that my code looks like so:

Code:
@Entity
@Table(name = "USER")
private class User {
    @Id
    @GeneratedValue
   private int userId;
   private List<Book> booksCheckedOut; // this can be Book[] booksCheckedOut if that helps
}

private class Book {
    @Id
    @GeneratedValue
   private int bookId;
   private String isbn;
}


and the schema for the User table looks like so and it's fixed and cannot be altered:

Code:
USER table:
INT USERID
INT BOOK1ID
INT BOOK2ID
INT BOOK3ID
INT BOOK4ID
INT BOOK5ID

BOOK table:
INT BOOKID
VARCHAR ISBN


How would I go about mapping the Book objects in the User object to the schema? Do I need to do some sort of custom field serialization such that when I retrieve or persist the Book objects it's mapped correctly? Or is my only option to create 5 Book objects in the User class (i.e. Book book1, Book book2 ... Book book5) and then map those to the columns via the @OneToOne annotation?

Thx in advance!

-Warren


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.