Win a copy of Learning Regular Expressions this week in the General Computing forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

ejb 3.0 entity issue  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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....
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!