-->
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 relation problems. Who can help me? it's urgent..
PostPosted: Wed Mar 15, 2006 8:12 am 
Newbie

Joined: Fri Mar 10, 2006 6:15 am
Posts: 4
Location: Italy
Hi all,

I have the following problem with Hibernate relation: one-to-one. I think it's not a very hard problem but I'm still stuffed into it.

I have two tables into my DB:

Entity
ID_Entity (PK) (Integer)
Name (String)
Address (String)
Entity_Type (FK) (Integer)

and

EntityType
ID_EntityType (PK) (Integer)
Description (String)


Entity_Type of Entity table is linked to ID_EntityType of EntityType table. It's much more easy to understand than to write it down :D

How can I compile the .hbm.xml files? I used in Entity.hbm.xml file the following tag:

Code:
<many-to-one name="EntityTypeDescription" column="Entity_Type"
                    class="EntityType"
                    property-ref="Description"
                    update="false"
                    insert="false"
                    unique="true"/>



and added two metohds get and set description into Entity Class.

But it doesn't work.

Can anybody help me please? it's urgent.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 15, 2006 12:17 pm 
Beginner
Beginner

Joined: Wed Nov 30, 2005 2:41 pm
Posts: 29
you don't want unique=true here - it's not unique within Entity. If you still have problems, post the EntityType hbm.xml also, and say WHAT does not work -- if makes it hard if we have to guess :)

---------
please rate if this helps!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 15, 2006 12:49 pm 
Newbie

Joined: Fri Mar 10, 2006 6:15 am
Posts: 4
Location: Italy
Thank you Dwightd for reply. My problem evolved because I went into many many tries, unsuccessfull until now. Before posting all my new code I advise you that, because of I'm from Italy, the classes names are in italian language.


Ente.hbm.xml

Code:
<?xml version="1.0"?>
<!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="siai.Ente" table="ENTE">
        <id name="idEnte" type="integer">
            <column name="ID_ENTE" />
            <generator class="native" />
        </id>
        <one-to-one name="tipoEnte" class="siai.TipoEnte" cascade="none" outer-join="auto" constrained="false">
           <formula>''</formula>
         </one-to-one>
        <property name="tipoEnteNome" type="integer">
            <column name="TIPO_ENTE_NOME" not-null="true" />
        </property>
        <property name="nome" type="string">
            <column name="NOME" length="45" not-null="true" />
        </property>
        <property name="indirizzo" type="string">
            <column name="INDIRIZZO" length="45" not-null="true" />
        </property>
        <property name="cap" type="string">
            <column name="CAP" length="45" not-null="true" />
        </property>
        <property name="comune" type="string">
            <column name="COMUNE" length="45" not-null="true" />
        </property>
        <property name="provincia" type="string">
            <column name="PROVINCIA" length="45" not-null="true" />
        </property>
        <property name="isDelegato" type="boolean">
            <column name="IS_DELEGATO" not-null="true" />
        </property>
        <property name="isStapf" type="boolean">
            <column name="IS_STAPF" not-null="true" />
        </property>
        <property name="stapfControllore" type="integer">
            <column name="STAPF_CONTROLLORE" not-null="true" />
        </property>
    </class>
</hibernate-mapping>


TipoEnte

Code:
<?xml version="1.0"?>
<!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="siai.TipoEnte" table="TIPO_ENTE">
        <id name="idTipoEnte" type="integer">
            <column name="ID_TIPO_ENTE" />
            <generator class="native" />
        </id>
        <property name="descrizione" type="string">
            <column name="DESCRIZIONE" length="45" not-null="true" />
        </property>
    </class>
</hibernate-mapping>


'Ente' class:

Code:
    ...
    private TipoEnte tipoEnte;
    ...
    public TipoEnte getTipoEnte(){
       return this.tipoEnte;
    }
   
    public void setTipoEnte(TipoEnte tipoEnte){
       this.tipoEnte = tipoEnte;
    }
   


With this situation I got a relationship between Ente's Primary Key and TipoEnte's Primary Key. Instead I wish a relation between Ente's TIPO_ENTE_NOME column and TipoEnte's Primary Key. How could I achieve this? Thank you very much for all help you could give me.


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.