-->
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: Auf den Discriminator zugreifen (wie) ?
PostPosted: Wed Aug 16, 2006 4:21 pm 
Regular
Regular

Joined: Mon Jul 31, 2006 4:59 pm
Posts: 53
Benutze Hibernate 3.2

Habe eine Tabelle für eine Klassenhierarchie angelegt. Hier die 3 Klassen:

Ressource (abstrakt)
Raum (erbt von Ressource)
Gegenstand (erbt von Ressource)

Allerdings weis ich nicht wie ich auf die Werte des Discriminators zugreifen soll. Hier mal das Mapping:


Code:
<hibernate-mapping>

   <class name="uebung9aPackage.Ressource" table="ressource" >
   
   
   <!-- das ID-Feld der Tabelle "ressource" -->
    <id name="id" column="id" type="long">
        <generator class="native"/>
    </id>
   
   
   <discriminator column="disc" type="string" length="1"/>

   <property name="name" column="name" type="string"/>

   
   <subclass name="uebung9aPackage.Raum" discriminator-value="r">
      <property name="gebaeude" column="gebaeude" type="string"/>
   </subclass>
   
   <subclass name="uebung9aPackage.Gegenstand" discriminator-value="g">
      <property name="wert" column="wert" type="string"/>
   </subclass>
   
   
   </class>
   
</hibernate-mapping>


Kann mir jemand sagen wie ich diesen Discriminator in eine HQL oder Criteria-Abfrage einbauen kann? Ich würde gerne meine Ergebnisse anhand des Discriminator-Wertes auswerten lassen (also ob die Subklasse nun ein Raum oder ein Gegenstand ist).
Jemand ne Idee?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 30, 2006 2:31 pm 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
In der Hibernate reference bei HQL nach where xy.class = Classname gucken. Das wird in eine Discriminator Abfrage übersetzt.

Sonst

select from SuperClass
loop
if (x instanceof ...)
tu das
else tu jenes

Gruß Sebastian

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


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.