Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

ejb 3.0 entity issue  RSS feed

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....
We cannot change unless we survive, but we will not survive unless we change. Evolving tiny ad:
Rocket Oven Kickstarter - from the trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!