-->
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.  [ 20 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: Fri Apr 22, 2005 11:10 am 
Senior
Senior

Joined: Tue Mar 02, 2004 6:17 pm
Posts: 151
emmanuel wrote:
The next draft will adress the abstract class isue, but not inheritance.
I'm thinking at the interface issue, but it's not simple to declare it through annotations.
In hbm, an interface is <subclass>ed by several classes. But I class has only 1 declared superclass or super interface.
This is different in an annotations approach.


Sorry, it seems we are experiencing a language barrier :( I didn't fully understand what you just said.

I understood: in HBM an interface may be subclassed by multiple classes but may have only one superclass. This is different in an annotation approach. Please correct me if I misunderstood.

Thing is, are you telling me that even without annotations, it is impossible to represent a class that implements multiple interfaces? That is, Hibernate only allows a single "implements" or "extends" statement per class? This would be problematic :(

As well, why is this different in annotations? Do they say we should be supporting this?

Thank you,
Gili


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 22, 2005 11:33 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
In association declaration ie targetEntity, you have to declare a *mapped* class/interface.
In Hibernate a mapped class can only have 1 single mapped superclass or interface.

There is no extends nor implements restriction of any kind.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 22, 2005 1:14 pm 
Senior
Senior

Joined: Tue Mar 02, 2004 6:17 pm
Posts: 151
emmanuel wrote:
In association declaration ie targetEntity, you have to declare a *mapped* class/interface.
In Hibernate a mapped class can only have 1 single mapped superclass or interface.

There is no extends nor implements restriction of any kind.


If I understand you correctly, you are saying I wouldn't be able to map the following inheritance in Hibernate even if I wasn't using Annotations:

interface Animal
{
public String getName();
}

interface Talks
{
public void talk();
}

class Dog implements Animal, Talks
{
Set<Dog> getFriends()
{
// body
}

// Implement getName(), talk()
}

Doesn't this imply that "ideally" we'd want Hibernate to support mapped classes implementing multiple interfaces? That is, this is not an annotation problem but rather one in Hibernate core?

Gili


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 02, 2005 5:23 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Of course you can do that, both in hbm and annotations.

What you cannot do is

Code:
<class name="Animal">
  <subclass name "Dog/>
</class>

<class name="Talk">
  <subclass name "Dog/>
</class>


ie set 2 super classes/interfaces for Dog.
Only mapped interfaces can be used as *explicit implementations* in Hibernate collections declaration (ie in the hbm file not the java class), eg

Code:
<class name="blah">
  <bag name="animals" class="Animals"/>
</class>

This bag will be able to get all declared subclasses of Animals (Dog in our example).

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Re: Annotations, inheritance and interfaces
PostPosted: Mon Jul 20, 2009 11:56 am 
Newbie

Joined: Mon Jul 20, 2009 11:52 am
Posts: 1
The discussion took place in 2005, has anything changed since?

Is it allowed to do this :

@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public interface Animal {}

@Entity
@DiscriminatorValue("Dog")
public class Dog implements Animal

Animal is mapped to the database, but "InheritanceType.SINGLE_TABLE" isn't taken into account so I have 2 tables: Animal and Dog. What am I doing wrong?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 20 posts ]  Go to page Previous  1, 2

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.