-->
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: First time using Hibernate
PostPosted: Thu Jan 06, 2005 6:15 pm 
Newbie

Joined: Thu Jan 06, 2005 5:58 pm
Posts: 3
Location: DTC
Hibernate version: 2.1

Mapping documents:

Project class:

<hibernate-mapping package="Metier">
<class name="Projet" table="PROJET">
<id
column="IDPROJ"
name="Idproj"
type="integer"
>
<generator class="vm" />
</id>
<property
column="DATEDEB"
length="10"
name="Datedeb"
not-null="false"
type="date"
/>
<property
column="DATEFIN"
length="10"
name="Datefin"
not-null="false"
type="date"
/>
<property
column="DESCRIPTION"
length="250"
name="Description"
not-null="false"
type="string"
/>
<property
column="DESIGNATION"
length="50"
name="Designation"
not-null="false"
type="string"
/>

<many-to-one
class="Budget"
name="Idbud"
not-null="true"
>
<column name="IDBUD" />
</many-to-one>
<set inverse="true" name="RISQUESet">
<key column="IDPROJ" />
<one-to-many class="Risque" />
</set>
<set inverse="true" name="PROCESSUSSet">
<key column="IDPROJ" />
<one-to-many class="Processus" />
</set>
<set inverse="true" name="METRIQUESet">
<key column="IDPROJ" />
<one-to-many class="Metrique" />
</set>
<set inverse="true" name="ITERATIONSet">
<key column="IDPROJ" />
<one-to-many class="Iteration" />
</set>
</class>
</hibernate-mapping>


Iteration classes :

<hibernate-mapping package="Metier">
<class name="Iteration" table="ITERATION">
<id
column="IDIT"
name="Idit"
type="integer"
>
<generator class="vm" />
</id>
<property
column="DATEDEB"
length="10"
name="Datedeb"
not-null="false"
type="date"
/>
<property
column="DATEFIN"
length="10"
name="Datefin"
not-null="false"
type="date"
/>
<property
column="NUMERO"
length="10"
name="Numero"
not-null="false"
type="integer"
/>

<many-to-one
class="Projet"
name="Idproj"
not-null="true"
>
<column name="IDPROJ" />
</many-to-one>
<set inverse="true" name="METRIQUESet">
<key column="IDIT" />
<one-to-many class="Metrique" />
</set>
<set inverse="true" name="TACHESet">
<key column="IDIT" />
<one-to-many class="Tache" />
</set>
</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
Session session = HibernateUtil.currentSession();
Transaction tx = session.beginTransaction();

Projet proj = new Projet(new Integer(0));
proj.setDesignation("projet qui pue");
Iteration it = new Iteration(new Integer(0));
proj.addToITERATIONSet(it);
session.save(it); // i try whith this line and whithout
session.save(proj);
tx.commit();

Full stack trace of any exception that occurs:
no execption throwed

Name and version of the database you are using:
Pointbase (with the j2ee 1.4)

The generated SQL (show_sql=true):
Hibernate: insert into ITERATION (DATEDEB, DATEFIN, NUMERO, IDPROJ, IDIT) values (?, ?, ?, ?, ?)
Hibernate: insert into PROJET (DATEDEB, DATEFIN, DESCRIPTION, DESIGNATION, IDBUD, IDPROJ) values (?, ?, ?, ?, ?, ?)


Comment:
The project class had a collection (set) of Iteration, when i had an iteration to the project , when i look into the database, the iteration foreign key refering the project id is null
Is someone can help me ??

_________________
°oO Pierrox Oo°


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 06, 2005 6:47 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
You also have to set the Project on the Iteration if you aren't doing that already.

i.e. your addToITERATIONSet(it) method should look something like this

iterationSet.add(it);
it.setProject(this);

Otherwise your Iteration has no knowledge of your project. I'm sure it's all covered in the reference docs. Read up on bidirectional associations.


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.