-->
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.  [ 5 posts ] 
Author Message
 Post subject: Both implementing interface and subclassing a class
PostPosted: Fri Aug 29, 2003 10:16 am 
Newbie

Joined: Fri Aug 29, 2003 10:03 am
Posts: 5
I have an folloving problem:
I have two classes Father and Son, that extends Father. I also have an interface Interface, that is implemented by the Son. Some getters and setters in the Father and Son manipulate with the Interface (they are typed to the Interface, but the object are instances of Son of course).
I have created an xml description of the mapping with tha <class>element for the Father and an <subclass> element for the Son, both with the right configured discriminator. When I try to run the program I get an exception, that says, that Interface isn't configured. When i add an <class> element for the Interface I get an exception, that says The Interface is an interface or abstract class, that can not be instantionised.
What should the maping look like for the situation, where I want to map a subclass of an already mapped class that implements an interface?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 29, 2003 3:27 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
How about you show the actual mapping that you currently have, and we can help you fix it.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 01, 2003 2:58 am 
Newbie

Joined: Fri Aug 29, 2003 10:03 am
Posts: 5
OK, it is a bit more complicated, that the first description, that has been designed to be as minimalist as possible:

There is part of acces-right system. There are objects, subjects and groups of subejcts and groups of objects. Each Subject is also an object and each Group of soemthing is also something. I would like to use this tree of infaritance:
Object
    -Group of objects
    -Subject
      -Group of subjects
it seems also usefull to have an interface Group, that is implemented bt Group of objects and group of subjects. Some getters and setters in the system use the type Group.

The connection classes are to provide many-to many relationship. I can't to use built-in one, for some reasons.

It sems to bee everything usefull, i remember. Ok, the last notice: of course I don't use the classname Object, names are in Czech and use here translation for your better orientation :)


<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class name="Object" table="object" discriminator-value="1">

<id name="id" type="long" column="id">
<generator class="sequence">
<param name="sequence">idsequence</param>
</generator>
</id>

<discriminator column="discriminator" type="int" />

<property name="domain" />
<property name="idVRamciDomeny" column = "id_v_domene" />

<subclass name="Subject" discriminator-value="4" >
<subclass name="GroupSubjects" discriminator-value="6" />
</subclass>

<subclass name="GroupObjects" discriminator-value="2" >
</subclass>

</class>

<class name="ConnectionSubjGroup" table="skupiny_subjektu" >
<id name="id" type="long" column="id">
<generator class="sequence">
<param name="sequence">idsequence</param>
</generator>
</id>
<many-to-one name="subject" />
<many-to-one name="group" />
</class>

<class name="ConnectionObjGroup" table="skupiny_predmetu" >
<id name="id" type="long" column="id">
<generator class="sequence">
<param name="sequence">idsequence</param>
</generator>
</id>
<many-to-one name="object" />
<many-to-one name="group" />
</class>

<class name="Group" table="object" discriminator-value="0">
<id name="id" type="long" column="id">
<generator class="sequence">
<param name="sequence">idsequence</param>
</generator>
</id>
<discriminator column="discriminator" type="int" />

</class>

</hibernate-mapping>


    Top
     Profile  
     
     Post subject: exception
    PostPosted: Mon Sep 01, 2003 3:49 am 
    Newbie

    Joined: Fri Aug 29, 2003 10:03 am
    Posts: 5
    net.sf.hibernate.HibernateException: Cannot instantiate abstract class or interface: Group


    Top
     Profile  
     
     Post subject: Solution
    PostPosted: Tue Sep 02, 2003 8:25 am 
    Newbie

    Joined: Fri Aug 29, 2003 10:03 am
    Posts: 5
    Change <many-to-one name="group" /> to <many-to-one name="group" class="Object" />
    This will cause, that the system will not try to guess the type of property by reflection (the result would be Group), but will search in the class hierarchy with the root in Object.


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