-->
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.  [ 3 posts ] 
Author Message
 Post subject: order by über mehrere tabellen
PostPosted: Tue Oct 24, 2006 7:11 am 
Newbie

Joined: Tue Oct 24, 2006 6:24 am
Posts: 7
hallo experten,
bin noch hibernate neuling und hätte folgende frage:

zuerst mal die db sowie die sourcen. es handelt sich bei dem problem um eine user/rollen berechtigungs-struktur.


DB-SCHEMA:
=========

SEC_ROLES
---------
ID
NAME


SEC_ROLES_KEYS
--------------
ID
ID_ROLE
ID_KEY
VALUE


SEC_KEYS
--------
ID
KEYNAME
DESCRIPTION
GROUPNAME


HIBERNATE-MAPPING:
==================
SNIP....
Code:
<class name="DboRole" table="SEC_ROLES">
      <id name="id" column="ID" type="long">
         <generator class="native"/>
      </id>
      <property name="name" column="NAME"/>
      <!-- Verknüpfung zu den usern -->
      <set name="users" table="SEC_USER_ROLES" lazy="false" fetch="join">
           <key column="ID_ROLE"/>
           <many-to-many column="ID_USER" class="DboUser"/>
       </set>
       <set name="roleKeys" lazy="false" fetch="join">
         <key column="ID_ROLE"/>
         <one-to-many class="DboRoleKey"/>
      </set>
   </class>
   
   <class name="DboRoleKey" table="SEC_ROLES_KEYS">
      <id name="id" column="ID" type="long">
         <generator class="native"/>
      </id>
      <property name="value" column="VALUE"/>
      <many-to-one name="key" column="ID_KEY" class="DboKey" lazy="false" fetch="select"/>
   </class>

   <class name="DboKey" table="SEC_KEYS">
      <id name="id" column="ID" type="long">
         <generator class="native"/>
      </id>
      <property name="keyName" column="KEYNAME"/>
      <property name="description" column="DESCRIPTION"/>
      <property name="groupName" column="GROUPNAME"/>
   </class>


...SNIP


gemappte KLASSEN:
================
Code:
public class DboRole {

   private Long id;
   private String name;
   private Set roleKeys = new HashSet();
   private Set users = new HashSet();
   ...
   
public class DboRoleKey {

   private Long id;
   private String value;
   private DboKey key;
   ...
   
public class DboKey {

   private Long id;
   private String keyName;
   private String description;
   private String groupName;
   ...

die Klassen haben alle die erforerdlichen getter und setter (public) und nichts ist final.


Jetzt mein Problem:
===================
Ich möchte eine Abfrage starten und dabei das Ergebnis (für das Frontend) sortieren.

Code:
List result = hSession.createQuery("from DboRole order by roleKeys.value")

funktioniert Problemlos, aber

Code:
List result = hSession.createQuery("from DboRole order by roleKeys.key.groupName")

nicht. ich erhalte dabei folgende Fehlermeldung:

Exception in thread "main" org.hibernate.QueryException: could not resolve property: groupName of: at.xxx.casey.core.dbo.mapping.DboRoleKey [from at.xxx.casey.core.dbo.mapping.DboRole order by roleKeys.key.groupName]
at org.hibernate.persister.entity.AbstractPropertyMapping.throwPropertyException(AbstractPropertyMapping.java:43)
at org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:37)
at org.hibernate.persister.entity.AbstractEntityPersister.toType(AbstractEntityPersister.java:1310)
at org.hibernate.persister.collection.AbstractCollectionPersister.toType(AbstractCollectionPersister.java:1435)
at org.hibernate.hql.ast.tree.FromElementType.getPropertyType(FromElementType.java:280)


Code:
List result = hSession.createQuery("from DboRole order by roleKeys.key.id")

liefert mir sogar eine NullPointer Exception

ich bin total ratlos. hab ich was falsch gemappt oder paßt die order-klausel nicht?
bitte vielmals um hilfe und danke im voraus.
Code:
Code:


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 29, 2006 4:01 pm 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
Du kannst nicht 1:n Beziehungen mit Punkt Notation durchwandern.

Versuch mal bitte:

Code:
List result = hSession.createQuery("from DboRole r left join r.roleKeys k order by k.key.groupName")

_________________
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  
 
 Post subject:
PostPosted: Mon Oct 30, 2006 5:27 am 
Newbie

Joined: Tue Oct 24, 2006 6:24 am
Posts: 7
LaLiLuna wrote:
Du kannst nicht 1:n Beziehungen mit Punkt Notation durchwandern.

Versuch mal bitte:

Code:
List result = hSession.createQuery("from DboRole r left join r.roleKeys k order by k.key.groupName")


alles klar, danke vielmals!

franky


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