-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 15 posts ] 
Author Message
 Post subject: Howto map implements of multiple interfaces
PostPosted: Thu Sep 15, 2005 3:03 pm 
Newbie

Joined: Thu Sep 15, 2005 10:04 am
Posts: 14
Hi,
I have a question on if it is possible (and how) to map a class which implements multiple interfaces. I want to map the interfaces as superclasses of the class (is mentioned as an approach in the manual), in addition I would like to query for instances of the class using either of the two interfaces (and their properties).

An example:
Interface IA has accessor getName
Interface IB has accessor getAge
Class CAB implements IA, IB
has two members name and age

I want to query for IA's using the name and (separately) for IB's for the age.

To map this I would like to use multiple extends entries in the subclass tag of the clas CAB (or another approach?).
However I don't think this is possible after reading the manual, looking (and debugging) in the Hibernate source code and trying it out.

Is there a(nother) way to model this in a mapping file? Or did I miss something obvious?

Any help is appreciated, thanks in advance,
Martin Taal


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 28, 2005 7:03 am 
It is realy blamefull, that the hibernate guys don't answer this essential question!!!


Top
  
 
 Post subject:
PostPosted: Mon Nov 28, 2005 7:26 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
I think you are looking for http://www.hibernate.org/148.html

But the basic answer is: No, multiple extends is not possible (and AFAIK not needed)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 28, 2005 7:51 am 
max wrote:
I think you are looking for http://www.hibernate.org/148.html

If you could explain my boss, why to invest money into consulting to an open source tool, well there is no problem for me.

max wrote:
(and AFAIK not needed)


It is needed because it is the common java way!
There are so many (partly unanswered) examples out there and of course in this forum, but here is one again:

Interface A

Interface B

Interface C

Class D implements A, B, C

Class E implements A, C

Class F
with a one-to-many association to "any thing that implements A"

How do you map D,E and F? Even if you only map the concrete class, you won't be able to have an association with a polymorphic type. You can't say, that the association may end to D because this crashes the E class and viceversa. You could introduce "intermediate classes" to get a single inheritence mapped with union-subclass(es).

But what if there is another class:

Class G extends H implements A, B

and the inheritence is already mapped using union-subclass? How do you build up intermediate classes now?

So the only thing, that hibernate should support is tagging any entity by various interfaces to support polymorphism to this interfaces in associations and queries.

AFAIK this is essential!

Regards,
Robert


Top
  
 
 Post subject:
PostPosted: Mon Nov 28, 2005 8:14 am 
Senior
Senior

Joined: Thu Aug 04, 2005 4:54 am
Posts: 153
Location: Birmingham, UK
rhk wrote:
If you could explain my boss, why to invest money into consulting to an open source tool, well there is no problem for me.


Because people haveissues that can't be answered by free help alone. Open source does not mean zero cost, it allows for zero cost in some instances and reduced cost in others. The hibernate team do need to eat, pay rent etc., and their business model is based around providing support to those who need more help than is freely available. Your boss as a business person should be capable of understanding a business model and being able to tell when it is necessary to pay experts to help.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 28, 2005 8:14 am 
Newbie

Joined: Thu Sep 15, 2005 10:04 am
Posts: 14
Hi,
Thanks rhk for bringing this (old post) back to the front and thanks Max for giving an answer.

As you understand Max I disagree that this is not needed. I think that it could be supported as rhk says. I guess for implicit polymorphism Hibernate already has some form of tagging.

gr. Martin


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 28, 2005 8:37 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
rhk wrote:
with a one-to-many association to "any thing that implements A"


Please guys, just listen: Max is 100% right, this is not needed. Polymorphic queries are enough.

An even if you disagree, Hibernate support this evil design. Read the doc. CTRL-F "any"


Quote:
It is realy blamefull, that the hibernate guys don't answer this essential question!!!

On a personal basis, this kind of statement is just shameful.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 28, 2005 8:59 am 
emmanuel wrote:
rhk wrote:
It is realy blamefull, that the hibernate guys don't answer this essential question!!!

On a personal basis, this kind of statement is just shameful.


Since I'm reading this forum, there are many questions from users unanswered even if they match the "how-to-ask-questions-faq" requirements.

Sure, many of these questions are answered before or are covered in the wiki or in the HiA book. But there are still questions that don't focus on any higher level to be answered only by commercial support.

Most of them needs just simple answers as Max's answer in this thread is.

So my comment is just resignation about the immense count of open questions that are not intend to be solved within a commercial support.

It is not the question of "open source = no cost". It's more: "What is a forum for?" Is the forum just only to advertise the commercial support but is a utility of developers to help a community to use their product.

At least it is a question of mindset to answer peoples analogous:
"Well, everything that was covered by hibernate is the reality and there is nothing out, that is still needed".

Please mull over about this, before refering to the commercial support!

Robert


Top
  
 
 Post subject:
PostPosted: Mon Nov 28, 2005 9:18 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Please rethink you position on this when you realise how many postings we have per day here and how many people and time that is needed to answer these questions!

If you want guaranteed response times then commercial support is for you.
If you don't need guaranteed answers then don't call us shamefull and ignorant.

We try and answer any question we can that makes sense, but we also have to let many slip since we simply don't have time to answer all questions - here the community should kick in, but they are also humans like us so they can also not cover every possible question.

And a forum is just not for developers to help a community to use their product, is for the community to help the community! (developers are part of the community too)....so start helping!

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 28, 2005 9:31 am 
max wrote:
so start helping!

So as I mentioned before:

Feature-Request:

Let entities to be tagged by various interfaces and let them be used in associations.

The <any> won't fit here, because I have to know ALL KIND of entities that could be concrete entities/tables for this - and this information is hard to write down in a "static" way into the mapping file, since I had to know what are all implementors of this interface.

ok, eclipse can show a list in the typ hierarchy explorer - but this doesn't help at all.

So the best solution would be:

Code:
<class name="BlaBla" tagged-by="interface1, interface2"> ... </class>
<class name="XYZ">
    ...
    <many-to-one name="abc" [b]tag[/b]="interface1" ...>
    ...
</class>


Where tagged-by="" contains a comma-separated list of either plain strings or plain strings that referes to entity- or classnames.

In opposition to the <any>-solution, the association in XYZ.abc do not require to know about all implementors of the interface1.

r.


Top
  
 
 Post subject:
PostPosted: Mon Nov 28, 2005 11:58 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
feature requests go to the jira, but in any case if you can write <many-to-one tag="interface1"/> why don't you just write <many-to-one class="BlaBla"> ?

Or just xml includes to handle this level of indirection ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 28, 2005 12:10 pm 
Because this would point me to the disadvantages of <any>:

I have to know which are all the implementors of interface1.

If there are more than one implementor, I cannot use the class="..." attribute


Top
  
 
 Post subject:
PostPosted: Mon Nov 28, 2005 12:18 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
so use xml entity includes and any.

create an entity include per interface and list the stuff needed.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 28, 2005 12:19 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
because it is still a *any* mapping you are doing - not a normal many-to-one. You still need to have two columns to identify where hibernate should go fetch the instance.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 28, 2005 12:37 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Banned, the first one in 4 months. Congratulations.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 15 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.