-->
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.  [ 2 posts ] 
Author Message
 Post subject: Does Hibernate Annotation support Interface mapping now?
PostPosted: Mon Apr 13, 2009 10:53 pm 
Newbie

Joined: Mon Apr 13, 2009 10:30 pm
Posts: 1
I need to mapping to a interface (since it has more than one implementation), but because JPA 1.0 spec doesn't support this, so I try to find solution using Hibernate Annotation, I googled some related topics and didn't find some useful information(some of them are too old, eg 2006,2007...)。 One solution I found was add "targetEntityClass" to @OneToOne and so on, but because my interface has many implementation its not a good answer. My code is like this:

Code:
public interface Foo{
...
}

public class FooA implements Foo{ ...}
public class FooB implements Foo{ ...}v

public class Bar {

    Foo foo;

}



Bar is an entity, how could I resolve the mapping using Hibernata Annotation?
Maybe i can introduce one AbstractFoo class, and use it as the "targetEntity" for foo.
Code:
public class Bar{

   @OneToOne(targetEntity = AbstractFoo.class)
   Foo foo;
}

public abstract class AbstractFoo implements Foo{ ... }

public class FooA extends AbstractFoo{ ... }

public class FooB extends AbstractFoo{ ... }


but I don't like this very much since it mix my design and implementation together. Does any one know any good solution?? Thanks.


Top
 Profile  
 
 Post subject: Annotations
PostPosted: Tue Apr 14, 2009 12:36 am 
Newbie

Joined: Mon Apr 13, 2009 7:45 am
Posts: 4
Hi Javeer

My experience with Hibernate is limited to the XML based mapping (not annotations), however, I can tell you that method-annotations declared on an interface will not "inherit" down to the actual methods that are implemented in your class / bean.

However - through reflection, it would be possible to interrogate a bean's interfaces, and determine if there are any annotations declared on the methods defined in the interface...

Not sure if Hibernate does that though... I would suggest implementing a simple example, and testing it yourself.

Good luck!


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