• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ejb 3.0 entity issue

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm diving into the new features of ejb 3.0. I'm trying to understand how to use ejb 3.0 entity beans effectivily in web apps.

I wrote a toy-app where I have 2 entity bean linked together by a ManyToMany relation: Book and Author.
I created some Author object and persisted them to DB via the EntityManager. Now I want to create a Book object and specify a set of Authors.
The only way I've seen to set authors for a newly created Book (since I used the ManyToMany relation) is to use the setAuthors method of Book object (annotated with ManyToMany) that accepts only a Collection of Authors.
This is to strict in my opionion. That's why. Suppose you have a jsp that lets you create a book by entering a title, ISBN, ... and choosing from a list a set of previously inserted authors. Obviously the info about the author is coded into the list (<select> by means of the primary key of author.
Now you press the submit button and the invoked servlet creates a new Book with the specified title and the other attributes. The problem comes with authors: to set authors for a book I have to create every Author object (with the given primary key), add every author to a Collection and then set the collection using the setAuthors method to the book. Wouldn't be better having a way to handle relations by specifying only the foreign key (that is the primary key of author)?

I'm afraid that what I wrote isn't clear enough....
 
reply
    Bookmark Topic Watch Topic
  • New Topic