Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EJB 3: Multiple (different) relations between two entities?

 
Johannes Koch
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to write an EntityBean that holds a collection of EntityBeans of another type plus two single references to EntityBeans of that type. A simple example would be a customer who has a work address and a home address, and a collection of previously used addresses that also need to be stored.

The classes could look like this:

However, I could not find any combination of annotations that would persist this setup in a sensible way. All the Addresses always get stored in one table, and I can't find a way to distinguish which address plays which "role" in the customer class when trying to write an SQL query to read them. I would especially like to avoid having to declare a Customer attribute in the Address class, since this would be redundant on the object level and would produce a lot of implementation overhead in my application.
Does anybody know how this can be done? I'm sure I am not the first person running into this need, but unfortunately, all the books, docs and tutorials I found don't cover it.
 
endswel shui
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you maybe the way will be ok

you can do that like this

[ July 03, 2008: Message edited by: endswel ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic