-->
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.  [ 9 posts ] 
Author Message
 Post subject: Interface as an Entity
PostPosted: Mon Nov 07, 2005 10:04 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
Hibernate version: 3.1

I get a NPE when annotating my interfaces with Entity annotation.

The code responsible:
Code:
AnnotationConfiguration.java

   private static void orderHierarchy(List<Class> copy, List<Class> newList, List<Class> original, Class clazz) {
      if ( Object.class.equals( clazz ) ) return;
      //process superclass first
      orderHierarchy( copy, newList, original, clazz.getSuperclass() );
      if ( original.contains( clazz ) ) {
         if ( !newList.contains( clazz ) ) {
            newList.add( clazz );
         }
         copy.remove( clazz );
      }
   }


Since Class.getSuperclass() method on an interface returns null.

Is this a bug?

Rgds, Ales

_________________
--------------------------------
Ales Justin
JBoss, a division of Red Hat


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 08, 2005 1:18 pm 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
Ok, I somehow tried to hack around this, but I see there is more to that than I was able to grasp.

Is there a plan to support interface annotation mapping support?

_________________
--------------------------------
Ales Justin
JBoss, a division of Red Hat


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 08, 2005 9:48 pm 
Beginner
Beginner

Joined: Sat Sep 17, 2005 10:41 am
Posts: 49
Doesn't really make sense since interfaces cannot have member variables that you can persist.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 3:27 am 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
+1 "Doesn't really make sense"


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 5:10 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
Hmm ... a lot of times it is useful to program to interfaces. And when doing this you would also like to have this interface mappable. Otherwise you cannot use it as a field reference in another Hibernate entity. Since annotation figure the type from returned class type. Or is there a way to tell to which mappable entity our field maps to?

For example:

Code:
private Payable payment; //interface

@Column(name="payment_id")
public Payable getPayment() {
  return payment;
}


But the actual mapped entity is AbstractPayable (since this one is an object, not an interface). How would I pass this information to the @Column annotation?

Since I might use this Payable interface in some other un mapped object and assign him a nonpresistent implementation.

Just thinking outloud ...

Rgds, Ales


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 7:41 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Quote:
@ManyToOne(targetEntity=AbstractPayable.class)
public Payable getPayment()


should work.

I plan to add interface support at some point but I don't like the concept in annotations. Contrary to the hbm xml files, the user will not really know what he's doint.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 08, 2007 5:00 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
Bit of a necro post here but has there been any movement on support of this? We've got a number of tables that have identical structures that we've built interfaces for.

i.e. an Auditable interface.

In this case it would be nice to be able to specify the annotation for the columns in the interface rather than copy the same annotation into every subclass or to have some sort of @MappedsuperClass that does this as our development team is starting to add multiple permutations of these interfaces bundled together in MappedsuperClasses which makes me sad.

Am I SOL? Or actually, is this a perfect example for an embedded mapping?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 10, 2007 7:29 am 
Newbie

Joined: Fri Apr 07, 2006 10:52 am
Posts: 17
Hi, it seems we have the same problem: http://forum.hibernate.org/viewtopic.php?t=971760

I am considering implementing the feature with the help of Emmanuel. Are you available for developing this?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 11, 2007 4:59 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
In my case I went with an Embedded mapping and it seems to be working for at least the one case. Where I really want the interface mapping I think is for our filtering usage. i.e. it would be nice to be able to define a DateEffective interface (which we do) that had the date binding filter on it. We used to do this with xdoclet but we've been moving everything over to annotations, slowly but surely.

Depending on the level of complexity of this (actually time) I might be able to convince the powers that be to slate some time for it since we'd most likely benefit from it although I'm still in the middle of reworking our domain objects so I'm not even sure I'll need this. I haven't really thought about it much so I'm not even really sure where to start.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 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.