-->
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-2-One relationship
PostPosted: Mon Mar 22, 2004 1:47 pm 
Newbie

Joined: Mon Oct 06, 2003 10:09 am
Posts: 3
I've got pretty simple mappings of one-2-one relationship generated by XDoclet. I try to persist a parent object, it doesn't throw any exception but it doesn't store any data into DB either.

Oracle9.2
Hibernate 2.1


Mapping:
<hibernate-mapping>
<class
name="com company.DocumentNM"
table="NM_DOCUMENT"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="id"
column="id"
type="java.lang.String"
>
<generator class="uuid.hex">
</generator>
</id>
<one-to-one
name="metadata"
class="com.company.Metadata"
cascade="all"
outer-join="auto"
constrained="false"
/>
<property
name="lastModifier"
type="java.lang.String"
update="true"
insert="true"
column="lastModifier"
not-null="true"
/>
<property
name="lastModified"
type="java.sql.Timestamp"
update="true"
insert="true"
column="lastModified"
not-null="true"
/>
</class>

</hibernate-mapping>

<hibernate-mapping>
<class
name="com.company.Metadata"
table="NM_METADATA"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="id"
column="id"
type="java.lang.String"
>
<generator class="foreign">
<param name="property">documentNM</param>
</generator>
</id>
<property
name="author"
type="java.lang.String"
update="true"
insert="true"
column="author"
/>
<property
name="title"
type="java.lang.String"
update="true"
insert="true"
column="title"
/>

<one-to-one
name="documentNM"
class="com.company.DocumentNM"
cascade="none"
outer-join="auto"
constrained="true"
/>
<property
name="lastModifier"
type="java.lang.String"
update="true"
insert="true"
column="lastModifier"
not-null="true"
/>
<property
name="lastModified"
type="java.sql.Timestamp"
update="true"
insert="true"
column="lastModified"
not-null="true"
/>
</class>
</hibernate-mapping>

Console output:

15:50:00,220 INFO [STDOUT] Hibernate: insert into NM_DOCUMENT (lastModifier, lastModified, id) values (?, ?, ?)
15:50:00,227 INFO [STDOUT] Hibernate: insert into NM_METADATA (author, title, lastModifier, lastModified, id) values (?, ?, ?, ?, ?)


Code:
{
DocumentNM doc = new DocumentNM();
Metadata meta = new Metadata();
meta.setAuthor("John Doe");
meta.setTitle("Test");
doc.setMetadata(meta);
meta.setDocumentNM(doc);

Session session = persistenceMgr.getInstance().getSession("test");
session.save(doc);
}
session.flush();


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 22, 2004 3:48 pm 
Regular
Regular

Joined: Tue Dec 02, 2003 6:25 pm
Posts: 61
Location: Dallas, TX
It doesn't look like you are committing your transaction.

try
Code:
Transaction tx = session.beginTransaction();
session.save(doc);
session.flush();
tx.commit();
session.close();


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.