• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Same entity - Two different tables

 
Ranch Hand
Posts: 995
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!

I was wondering how the following can be solved:
Let's say we have 3 entities: A, B, C whose relation is:
A uses a collection of C
B uses a collection of C.
C entity must be mapped to 2 different tables TBL_AC, respective TBL_BC.

Is it a case for inheritance? How should it be done?
 
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Is it a case for inheritance?



I think, it's not case for inheritant because relation is seem like composition or not??





How should it be done?



You can use Collection Mapping for solve this problem.

AT :: http://www.hibernate.org/hib_docs/reference/en/html/collections.html
 
Alexandru Popescu
Ranch Hand
Posts: 995
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is absolutely the case for Collection mappings. My question was about the definition/mapping of the C entity. The most simple thing to do is to use a component in A, resp. B to describe C, but this results in mapping duplication... and I was asking if this can be refactored ;-).
 
author
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure exactly which kind of mapping you are trying to do, but I know that you can do it in Hibernate3 (and not in Hibernate 2.1). (There is a couple of different things you might mean.)
 
Alexandru Popescu
Ranch Hand
Posts: 995
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Gavin King:
but I know that you can do it in Hibernate3 (and not in Hibernate 2.1).


LOL Hibernate3 is meant to be some Superman Hibernate? (just kidding).

To clarify my question:
Let's take for example a Person - Address relation (1-N) and also Office - Address relation (1-N), in which Address entity *must* be persisted to different tables (the example is not so good :-( - let's say even if Address has the same structure, it has different meanings while related to Person or Office).

My question is about how I can describe in a single place the Address entity? (I think the question is on the field of *joined-subclass* - I should define DefaultAddress and than 2 extends: PersonAddress and OfficeAddress and use them ... hmmm)
 
Gavin King
author
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, for Address, it probably makes most sense to use a <component> or <composite-element>. In any version of Hibernate.
 
Alexandru Popescu
Ranch Hand
Posts: 995
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But this way I will write down the same mapping two times, ain't it?
 
Gavin King
author
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use an XML external entity declaration.
 
Alexandru Popescu
Ranch Hand
Posts: 995
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nice idea... but I am sorry to accept I do not know how to do this [sigh/]
 
Gavin King
author
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://www.gca.org/papers/xmleurope2000/papers/s14-02.html#N57276
 
Alexandru Popescu
Ranch Hand
Posts: 995
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
10x Gavin - I thought it was something specific to Hibernate. That method I know it from Ant :-). However, many 10x.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic