-->
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.  [ 1 post ] 
Author Message
 Post subject: one-to-one mapping Problem
PostPosted: Fri Jul 30, 2004 5:11 pm 
Newbie

Joined: Wed Jan 28, 2004 5:21 pm
Posts: 18
Location: Maracaibo, VZLA
Hi everybody !!!
I'm dealing with a association that it drives me crazy.... I'll be happy if someone could help me !!
This is the prblem:
I have to table Document (Parent) and DocumentType (Child), both has it fields and the primary key of the table Document is referenced of the Primary key of the table DocumentTypeA

CREATE TABLE [DocumentTypeA] (
[idDocumentTypeA] [int] NOT NULL ,
[txt1] [text] COLLATE Modern_Spanish_CI_AS NOT NULL ,
[txt2] [text] COLLATE Modern_Spanish_CI_AS NULL ,
CONSTRAINT [PK_DocumentTypeA] PRIMARY KEY CLUSTERED(
[idDocumentTypeA] ) ON [PRIMARY] ,
CONSTRAINT [FK_DocumentTypeA_Document] FOREIGN KEY (
[idDocumentTypeA]) REFERENCES [Document] (
[idDocument]))
ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]


I'm using middlegen to generate the mapping file, and it genereted the following map

<class name="com.ped.impl.DocumentTypeAImpl"
table="DocumentTypeA">
<id name="idDocumentTypeA" type="int" column= "idDocumentTypeA">
<generator class="foreign">
<param name="property">doc</param>
</generator>
</id>
<property
name="txt1"
type="java.lang.String"
column="txt1"
not-null="true"
length="2147483647" />
<property
name="txt2"
type="java.lang.String"
column="txt2"
length="2147483647" />

<!-- associations -->
<!-- bi-directional one-to-one association to InformeMedico -->
<one-to-one
name="doc"
class="com.ped.impl.Document"
outer-join="auto" />


and finally I do this in my app
Document document = new Document();
/* I load the values for this class */
DocumentTypeA documentTypeA = new DocumentTypeA();
/* I load the values for this class */
document.setdocumentTypeA(documentTypeA);
documentTypeA.setdocument(document);
session.save(document);

but when I run the app the server throw me the following message:

java.sql.SQLException: INSERT statement conflicted with COLUMN FOREIGN KEY constraint 'FK_DocumentTypeA_Document'. The conflict occurred in database 'TEST', table 'Document', column 'idDocument'.

it seems like hibernate is trying to insert DocumentTypeA before insert Document... !!!


Does anyone knows what's wrong ??
Thanks in advances
Alejandro.-


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.