-->
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.  [ 1 post ] 
Author Message
 Post subject: one-to-one assoziation mit bedingung im mapping
PostPosted: Thu Jan 04, 2007 6:00 am 
Beginner
Beginner

Joined: Thu Jan 04, 2007 5:44 am
Posts: 26
Location: Innsbruck - Sivas(TR) - Bregenz
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3


Mapping documents:

Code:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
    Mapping file autogenerated by MyEclipse - Hibernate Tools
-->
<hibernate-mapping>
    <class name="com.ternasoft.crm.model.Kunde" table="kunde" catalog="hds_test">
        <id name="kundenid" type="java.lang.Integer">
            <column name="kundenid" />
            <generator class="increment" />
        </id>
        <many-to-one name="firma" class="com.ternasoft.crm.model.Firma" fetch="select">
            <column name="firmaid" />
        </many-to-one>
        <many-to-one name="agentByAgent" class="com.ternasoft.crm.model.Agent" fetch="select">
            <column name="agent" />
        </many-to-one>
        <many-to-one name="filiale" class="com.ternasoft.crm.model.Filiale" fetch="select">
            <column name="filiale" />
        </many-to-one>
        <many-to-one name="agentByTerminvereinbarer" class="com.ternasoft.crm.model.Agent" fetch="select">
            <column name="terminvereinbarer" />
        </many-to-one>
        <many-to-one name="kundenstatus" class="com.ternasoft.crm.model.Kundenstatus" fetch="select">
            <column name="kstatus" />
        </many-to-one>
        <many-to-one name="karte" class="com.ternasoft.crm.model.Karte" fetch="select">
            <column name="kartenid" not-null="true" />
        </many-to-one>
        <property name="telefon" type="java.lang.String">
            <column name="telefon" length="20" />
        </property>
        <property name="email" type="java.lang.String">
            <column name="email" length="50" not-null="true" />
        </property>
        <property name="aktivierungsdatum" type="java.util.Date">
            <column name="aktivierungsdatum" length="19" />
        </property>
        <property name="letztlogin" type="java.util.Date">
            <column name="letztlogin" length="19" />
        </property>
        <property name="aktivierungscode" type="java.lang.String">
            <column name="aktivierungscode" length="10" />
        </property>
        <property name="fremdkundenid" type="java.lang.Integer">
            <column name="fremdkundenid" />
        </property>
        <property name="importStamp" type="java.lang.String">
            <column name="importStamp" length="17" />
        </property>
        <property name="beginn" type="java.util.Date">
            <column name="beginn" length="10" />
        </property>
        <property name="ende" type="java.util.Date">
            <column name="ende" length="10" />
        </property>
        <set name="persons" inverse="true">
            <key>
                <column name="kundenid" />
            </key>
            <one-to-many class="com.ternasoft.crm.model.Person" />
        </set>
        <set name="notizs" inverse="true">
            <key>
                <column name="kundenid" />
            </key>
            <one-to-many class="com.ternasoft.crm.model.Notiz" />
        </set>
        <set name="zahlungsdatens" inverse="true">
            <key>
                <column name="kundenid" />
            </key>
            <one-to-many class="com.ternasoft.crm.model.Zahlungsdaten" />
        </set>
    </class>
</hibernate-mapping>




Code:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
    Mapping file autogenerated by MyEclipse - Hibernate Tools
-->
<hibernate-mapping>
    <class name="com.ternasoft.crm.model.Person" table="person" catalog="hds_test">
        <id name="personid" type="java.lang.Integer">
            <column name="personid" />
            <generator class="increment" />
        </id>
        <many-to-one name="land" class="com.ternasoft.crm.model.Land" fetch="select">
            <column name="land" />
        </many-to-one>
        <many-to-one name="kunde" class="com.ternasoft.crm.model.Kunde" fetch="select">
            <column name="kundenid" />
        </many-to-one>
        <property name="titel" type="java.lang.String">
            <column name="titel" length="10" />
        </property>
        <property name="anrede" type="java.lang.String">
            <column name="anrede" length="10" />
        </property>
        <property name="vorname" type="java.lang.String">
            <column name="vorname" length="20" not-null="true" />
        </property>
        <property name="nachname" type="java.lang.String">
            <column name="nachname" length="20" />
        </property>
        <property name="strasse" type="java.lang.String">
            <column name="strasse" length="50" />
        </property>
        <property name="plz" type="java.lang.String">
            <column name="plz" length="10" not-null="true" />
        </property>
        <property name="ort" type="java.lang.String">
            <column name="ort" length="50" not-null="true" />
        </property>
        <property name="istkunde" type="java.lang.Byte">
            <column name="istkunde" not-null="true" />
        </property>
        <property name="telefon" type="java.lang.String">
            <column name="telefon" length="50" />
        </property>
        <property name="email" type="java.lang.String">
            <column name="email" length="100" />
        </property>
        <property name="geburtsdatum" type="java.util.Date">
            <column name="geburtsdatum" length="10" />
        </property>
        <set name="bestellungs" inverse="true">
            <key>
                <column name="personid" not-null="true" />
            </key>
            <one-to-many class="com.ternasoft.crm.model.Bestellung" />
        </set>
    </class>
</hibernate-mapping>






Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:
MySql


The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Hallo habe eine Kundentabelle mit 1:N Assoziation zu einer Persontabelle. Ich würde gerne zusätzlich eine one-to-one Assoziation vom Kunden zur Person machen und zwar zur Person mit dem Attributwert "istkunde=1"

Das heisst in SQL

Code:
Select * from Kunde,Person where Kunde.kundenid=Person.kundenid and Person.istkunde=1


Ich habe es jetzt so gelösst das ich im kunde pojo eine methode getHauptperson habe wo ich dann alle Personen durchiteriteriere und die Hautpterson in kunde dann setze wenn istkunde=1

Gibt es eine möglichkeit in der Kunde.hbm.xml eine one-to-one Assoziation zu setzen mit einer join bedingung.

danke im voraus

Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html

Code:


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.