-->
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: one-to-one persist problem
PostPosted: Fri Oct 21, 2005 3:29 am 
Newbie

Joined: Wed Jul 07, 2004 5:35 am
Posts: 7
Location: L
Hibernate version: 2

Mapping documents: Aufgabe.hbm.xml , Pruefung.hbm.xml, Kategorie.hbm.xml

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 4.0.21

The generated SQL (show_sql=true):
insert into Aufgaben (ueberschrift, inhalt, bild1, bild2) values (?, ?, ?, ?)
select this.aufgabenID as aufgabenID2_, this.ueberschrift as uebersch2_2_, this.inhalt as inhalt2_, this.bild1 as bild12_, this.bild2 as bild22_, kategorie1_.kategorienID as kategori1_0_, kategorie1_.name as name0_, pruefung2_.pruefungenID as pruefung1_1_, pruefung2_.erscheinungsjahr as erschein2_1_, pruefung2_.fachbereich as fachbere3_1_, pruefung2_.pruefungsPDF as pruefung4_1_, pruefung2_.pruefungsPDF2 as pruefung5_1_ from Aufgaben this left outer join Kategorien kategorie1_ on this.aufgabenID=kategorie1_.kategorienID left outer join Pruefungen pruefung2_ on this.aufgabenID=pruefung2_.pruefungenID where 1=1


Debug level Hibernate log excerpt: logging not configured yet


Hi all,

i have a problem with two one-to-one associations. When i want to save my Aufgaben object which holds two one-to-one associations, one to Kategorie and one to Pruefung, the keys of the associated objects are not saved into the db. I have searched this forum for similar problems but couldn't find an answer to my problem. Can Hibernate not store the id's of one-to-one associated objects? Or does Hibernate not note that the associations are properties of the parent object too?
Would be nice if someone could help me! Below are my DB Tables and the mapping files.
Thanks in advance.

Torben

Database Tables
--------------------
Code:
Table Aufgaben (
aufgabenID INTEGER PK AUTO_INCREMENT,
kategorienID INTEGER FK,
pruefungenID INTEGER FK,
ueberschrift VARCHAR,
inhalt VARCHAR
)

Table Kategorien (
kategorienID INTEGER PK AUTO_INCREMENT,
name VARCHAR
)

Table Pruefungen (
pruefungenID INTEGER PK AUTO_INCREMENT,
erscheinungsjahr INTEGER,
fachbereich VARCHAR
)


Mapping files
---------------
Aufgabe.hbm.xml:
Code:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping
    PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
   
<hibernate-mapping>
    <class name="cactus.dom.Aufgabe" table="Aufgaben">
       
        <id name="aufgabenID" column="aufgabenID" type="int">
            <generator class="native"/>
        </id>
           
        <property name="ueberschrift" column="ueberschrift"     
            type="string" not-null="true"/>
        <property name="inhalt" column="inhalt" 
            type="string" not-null="true"/>
           
        <one-to-one
           name="kategorie"                               
           class="cactus.dom.Kategorie"                                 
           cascade="none"
           foreign-key="kategorienId"/>
       
        <one-to-one
           name="pruefung"                               
           class="cactus.dom.Pruefung"                                 
           cascade="none"
           foreign-key="pruefungenId"/>
       
    </class>
</hibernate-mapping>



Kategorie.hbm.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping
    PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
   
<hibernate-mapping>
    <class name="cactus.dom.Kategorie" table="Kategorien">
       
        <id name="kategorienID" column="kategorienID" type="int">
            <generator class="native"/>
        </id>
           
        <property name="name" column="name"     
            type="string" not-null="true"/>
       
    </class>
</hibernate-mapping>



Pruefung.hbm.xml
Code:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping
    PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
   
<hibernate-mapping>
    <class name="cactus.dom.Pruefung" table="Pruefungen">
       
        <id name="pruefungenID" column="pruefungenID" type="int">
            <generator class="native"/>
        </id>
           
        <property name="erscheinungsjahr" column="erscheinungsjahr"
           type="int" not-null="true"/>
        <property name="fachbereich" column="fachbereich"
           type="string" not-null="true"/>
       
    </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject: solved
PostPosted: Fri Oct 21, 2005 4:13 am 
Newbie

Joined: Wed Jul 07, 2004 5:35 am
Posts: 7
Location: L
problem solved. i must use many-to-one associations to get it work. thanks anyway guys.

bye

torben


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.