-->
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.  [ 4 posts ] 
Author Message
 Post subject: Returning interface in many-to-one methods
PostPosted: Wed Aug 27, 2003 6:25 am 
Beginner
Beginner

Joined: Wed Aug 27, 2003 6:15 am
Posts: 22
Hi

I have a parent/child relationship (tables P and C). My Java classes are PImpl.java and CImpl.java. Two interfaces, P.java and C.java, are implemented by parent and child respectively, i.e.,

public class CImpl implements C { ... }
public class PImpl implements P { ... }

Currently, I define C.getP() to return P the interface, i.e.,

public P getP() { return this.p; }

However, it seems that for C to return P, P must have its own mapping file. At runtime, I'm getting an exception saying that P is an interface or abstract class and cannot be instantiated. On the other hand, if getP() is to return the concrete P, the method signature has to be:

public PImpl getP()

which is not what I want. So, my question is, how do I do this properly?

I've attached the runtime exception I've got when Hibernate tried to instantiate the interface. Thanks.

cirrus.hibernate.HibernateException: Cannot instantiate abstract class or interface: P
at cirrus.hibernate.persister.AbstractEntityPersister.instantiate(AbstractEntityPersister.java:301)
at cirrus.hibernate.loader.Loader.getRow(Loader.java:301)
at cirrus.hibernate.loader.Loader.doFind(Loader.java:160)
at cirrus.hibernate.loader.Loader.loadEntity(Loader.java:503)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 27, 2003 6:32 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
All this information is completely useless w/o a mapping file.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 27, 2003 10:08 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Code:
<class name="PImpl" table="P_TABLE" proxy="P">
   ...
</class>
<class name="CImpl" table="C_TABLE" proxy="C">
    ...
    <many-to-one name="p" class=PImpl" column="P_ID"/>
</class>
public interface P {}
public interface C { public P getP(); }

public class PImpl implements P {}
public class CImpl implements C
{
    private P p;
    public P getP() { return p; }
    public void setP( P p ) { this.p = p; }
}


Top
 Profile  
 
 Post subject: It works!
PostPosted: Wed Aug 27, 2003 9:11 pm 
Beginner
Beginner

Joined: Wed Aug 27, 2003 6:15 am
Posts: 22
Hi Steve

It works now. The problem arose because I also have a one-to-many relationship from parent to child. I incorrectly put the interface name of the child in the <set> element. Once I've resolved to use the concrete class names it works just fine now.

Thanks a lot!


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