-->
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.  [ 6 posts ] 
Author Message
 Post subject: How to map Interfaces and their implementing classes?
PostPosted: Wed Dec 10, 2003 5:31 am 
Newbie

Joined: Mon Dec 08, 2003 1:44 pm
Posts: 16
Location: Germany
Hello!

I have several JAVA-Interfaces: a QUESTION and an ANSWER. The QUESTION-Interface is extended by two more interfaces: NumericQUESTION and TextQUESTION. The ANSWER-Interface is extended by the interfaces NumericANSWER and TextANSWER.

Each Interface is implemented by a Class with Name [InterfaceName]+DTO, i. e. QUESTION is implemented by QuestionDTO. The "DTO" stands for "Data Transfer Object".

Now I want to express that each subclass of AnswerDTO, that is NumericAnswerDTO and TextAnswerDTO, knows about its corresponding question. So NumericAnswerDTO has an attribute "question". The type of the attribute is the one of the interface! Here is a code example:

Code:
public class TextAnswerDTO extends AnswerDTO implements TextAnswer {

//... some inherited attributes

// Now the linkage to the corresponding question
TextQuestion question;

// ... Constructors

public void setQuestion(TextQuestion q) throws AnException {
this.question = q;
}

public TextQuestion getQuestion() throws AnException {
return question;
}

}


The relation between answers and questions is many-to-one, which means that many answers are related to one question.

How can I map this scenario? The classes that are obviously persistet to the database are the DTOs, I use the interfaces to add a level of abstraction, so I can later change the underlying implementation. But it is very important, that the attributes of the DTO-classes holding the reference to a corresponding question are of the interface type!

Thanks for all help in advance!

Philipp Hinnah (Germany)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 10, 2003 11:20 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
chapter 5.1.3 helps ?

_________________
Emmanuel


Top
 Profile  
 
 Post subject: I think I found a solution...
PostPosted: Wed Dec 10, 2003 5:13 pm 
Newbie

Joined: Mon Dec 08, 2003 1:44 pm
Posts: 16
Location: Germany
... yeah, it helps. I've read over this several times. Maybe I should try this with the mapping of implementing classes by the <subclass>-element.

Thx!


Top
 Profile  
 
 Post subject: I still got a problem
PostPosted: Thu Dec 11, 2003 6:41 am 
Newbie

Joined: Mon Dec 08, 2003 1:44 pm
Posts: 16
Location: Germany
Here is my first attempt to map a part of the scenario I described above.

Code:
<!-- Interface Question -->
    <class name="org.openuss.group.specification.business.Question" table="QUESTION" discriminator-value="Question">
        <id name="id" column="ID">
            <generator class="uuid.string" />
        </id>
        <discriminator column="CLASS_NAME" />
        <property name="text" column="TEXT" not-null="true" />
        <many-to-one name="parentQuestion" column="PARENT_ID" class="org.openuss.group.specification.business.Question" />
       
        <!-- Implementing Class QuestionDTO -->
        <subclass name="org.openuss.group.business.entity.QuestionDTO" discriminator-value="QuestionDTO" />
       
        <!-- Subclass (Subinterface) TextQuestion -->
        <subclass name="org.openuss.group.specification.business.TextQuestion" discriminator-value="TextQuestion">
            <property ... />
           
            <!-- Implementing Class TextQuestionDTO -->
            <subclass name="org.openuss.group.business.entity.TextQuestionDTO" discriminator-value="TextQuestionDTO" />
           
        </subclass>
    </class>


Is this correct? The Hibernate Reference says to use the <subclass>-Tag to declare implementing classes of the interface. But I also need to use the <subclass>-Tag to declare a subinterface ("TextQuestion") of the interface "Question". And then I use this tag once again to declare the implementing class of the "TextQuestion" interface.

I am really wondering, if this solution works?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 11, 2003 6:42 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
sure, why not. did you try it??


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 11, 2003 7:42 am 
Newbie

Joined: Mon Dec 08, 2003 1:44 pm
Posts: 16
Location: Germany
Not yet... I haven't installed Hibernate yet. I am working in a 6-member-team on a 3-tier software development. We use Hibernate instead of Entity Beans for the data layer.

But I am quite a newbie... so I first need to understand how to set up the whole Hibernate-Environment and how to access the database (we use HyperSonicSQL) via sessions... but I will learn... :-)

I think future posts of mine will follow when the first errors occur?


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