• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

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

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic