[hibernate-issues] [Hibernate-JIRA] Commented: (ANN-9) Support interface inheritance mapping

Paul Singleton Kossler (JIRA) noreply at atlassian.com
Fri Mar 7 14:14:35 EST 2008


    [ http://opensource.atlassian.com/projects/hibernate/browse/ANN-9?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_29734 ] 

Paul Singleton Kossler commented on ANN-9:
------------------------------------------

I am curious as the state of this improvement.  It is mentioned in the "Java Persistence with Hibernate "from Manning press. Though the last traffic on this was a year ago.  This feature helps the community by reducing the complexity of the build environment as well as reducing the number of files to track per class.

@Entity can handle mapping an Interface as follows:

//-----------------
@Entity
public interface A {
   @Transient
   public B getB();

   public void setB(B b);

   @Transient
   public C getC();

   public void setC(C c);
}

public class B{}
public class C{}
//------------------------
In this case a a simple POJO getter/setter can be mapped with @Transient to denote that the 
actual persistence mapping annotations are only on the abstract or concrete class that actually contains information to be persisted.

Since a Java interface is the same as a pure virtual class in C one could take this one step further and allow @Transient assignment at the Class level.
This would denote that this class is not a class it is an interface (Can be checked with a guard on compile)
This would allow the SessionManager to determine the type of Entity: Real or Reference for class and interfaces respectively.

I may be going down a side path in this thought process; however, the @org.hibernate.annotations.Entity could also have an addition attribute "interface" such that:
@org.hibernate.annotations.Entity(interface="true") 
defaulting to false; will keep this inline with the JPA spec and as an extension of a class level annotation this makes the @Transient annotations redundant so the Interface could be mapped more simply too:

//-----------------
@Entity(interface="true")
public interface A {
   public B getB();

   public void setB(B b);

   public C getC();

   public void setC(C c);
}

public class B{}
public class C{}
//------------------------

I hope this helps out other developers.

If I am inaccurate on the forum/implementation level I do apologize.  Unfortunately looking up the word "interface" with Hibernate and Java is ambiguous, making it difficult to narrow in on.

> Support interface inheritance mapping
> -------------------------------------
>
>                 Key: ANN-9
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/ANN-9
>             Project: Hibernate Annotations
>          Issue Type: Improvement
>          Components: binder
>    Affects Versions: 3.1beta3
>            Reporter: Gili
>         Attachments: hibernate3-annotations-3.1beta5-3896-3948.diff, hibernate3-annotations-3.1beta5-3896-4138.diff
>
>
> It should be possible to create a mapping with interfaces, as described by the documentation here: http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#inheritance-tableperclass
> Specifically right now it is impossible to annotate interfaces and according to HBX-231 even if you could @Entity is only meant to get used on classes so the question becomes "what do you annotate it with?"
> As I pointed out here http://forum.hibernate.org/viewtopic.php?p=2238824#2238824 the additional problem seems to be that XDoclet doesn't support interface annotation either (http://opensource.atlassian.com/projects/xdoclet/browse/XDT-1345) so I'm left without a workaround.
> I can't convert the interfaces to abstract classes because I implement multiple interfaces in my application and Java does not do multiple inheritance.
> If you know of a nice workaround, please let me know :)

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list