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.-
|