-->
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: one-to-one mapping with condition
PostPosted: Thu Jan 04, 2007 6:30 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:

Hi, I have a "Kunde" table with one-to-many association to a "Person" table. I would also add a one-to-one association to a "Person" with a condition "istkunde=1". For example this is like when I have a customer with some adresses and I have one mainadress wich is marked as attribut in the table like mainadress=1.

This look in my case in sql like the following:

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


I resolve it yet with iterating the set Persons in the Kunde-pojo and find the Person with the attribute istkunde=1.

best regards

Problems with Session and transaction handling?

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

Code:


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 04, 2007 6:58 am 
Senior
Senior

Joined: Sun Jun 04, 2006 1:58 am
Posts: 136
have you tried using a filter ....??

Quote:
http://www.hibernate.org/hib_docs/v3/reference/en/html/filters.html

_________________
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 04, 2007 8:33 am 
Beginner
Beginner

Joined: Thu Jan 04, 2007 5:44 am
Posts: 26
Location: Innsbruck - Sivas(TR) - Bregenz
scarface wrote:
have you tried using a filter ....??

Quote:
http://www.hibernate.org/hib_docs/v3/reference/en/html/filters.html


you mean tha I use a one-to-one in my Kunde.hmb.xml and use a filter in it like this
Code:
.....
<one-to-one name="MainPerson"
   <filter name="mainPersonFilter" condition=":istkunde=1"/>
....


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.