-->
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: Typesafe Many-To-Many Query
PostPosted: Fri Aug 22, 2008 6:24 am 
Newbie

Joined: Fri Aug 22, 2008 6:12 am
Posts: 13
Hallo,

ich habe ein Problem mit HQL eine typsichere Anfrage zu machen, in der ich nur bestimmte Spalten aus einer Tabelle abfrage. Meine DB sieht so aus:


Code:
public class Mails {
    private long mail_id;
    private String absender;
    private String betreff;
    private Date datum;
    private int spamLevel;
    private String spamReport;
    private Blob mail;
    private Set adressen;
}


Code:
public class Empfaenger implements Serializable {
    private long empfaenger_id;
    private String adresse;
    private Set emails = new LinkedHashSet();


Code:
<hibernate-mapping default-lazy="false">
    <class name="com.os.admin.spamcontrol.entities.Mails" table="mails">

        <id name="mail_id" type="long" unsaved-value="null">
            <generator class="native"/>
        </id>
        <property name="absender" type="string" length="70"/>
        <property name="betreff" type="string" length="500"/>
        <property name="datum"/>
        <property name="spamLevel" type="int" length="7"/>
        <property name="spamReport" type="text" length="1000"/>
        <property name="mail" type="blob" not-null="true" lazy="true"/>
        <set name="adressen" table="mails_empfaenger" fetch="join">
            <key column="mail_id"/>
            <many-to-many column="empfaenger_id" class="com.os.admin.spamcontrol.entities.Empfaenger"/>
        </set>
    </class>
</hibernate-mapping>


Code:
<hibernate-mapping default-lazy="false">
    <class name="com.os.admin.spamcontrol.entities.Empfaenger" table="empfaenger">
        <id name="empfaenger_id" type="long" unsaved-value="null">
            <generator class="native"/>
        </id>
        <property name="adresse" type="string" length="70"/>

        <set name="emails" inverse="true" table="mails_empfaenger">
            <key column="empfaenger_id"/>
            <many-to-many column="mail_id" class="com.os.admin.spamcontrol.entities.Mails"/>
        </set>

    </class>
</hibernate-mapping>


Jetzt würd ich gerne alles außer Blob mail abfragen und zwar typsicher.

Hab's mit solchen Abfragen versucht, klappt aber nicht wirklich:

Code:
select new Mails (m.mail_id, m.absender, m.betreff, m.datum, m.spamLevel, m.spamReport, m.adressen)


oder auch:

Code:
select new Mails (m.mail_id, m.absender, m.betreff, m.datum, m.spamLevel, m.spamReport, a) from Mails m inner join fetch m.adressen as a


Würd mich sehr freuen, wenn jemand mir helfen könnte.

Danke schon mal im Voraus


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 09, 2008 4:46 am 
Newbie

Joined: Fri Aug 22, 2008 6:12 am
Posts: 13
Keiner 'ne Idee? Ich würde mich auch über eine Lösung mit Criteria Queries oder irgend wie anders freuen ...


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.