-->
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.  [ 4 posts ] 
Author Message
 Post subject: one-to-one (AGAIN)
PostPosted: Mon Oct 06, 2003 5:42 am 
Newbie

Joined: Mon Oct 06, 2003 5:35 am
Posts: 9
Location: Perth.au
Hi Folks,

I am still battling with the one-to-one mapping, with the Hibernate 2.0 there is the foreign key index for the child but I don't seem to have much luck at getting it to work.

Does the relationship have to be bi-directional ?

My definition are : -

<class name="Document"
table="DOCUMENT"
dynamic-update="false"
dynamic-insert="false" >

<id name="id"
column="DOC_ID"
type="java.lang.Long"
unsaved-value="null" >

<generator class="sequence">
<param name="sequence">DOC_SEQ</param>
</generator>
</id>


<property name="OWNER"
type="java.lang.String"
column="OWNER"
length="255" />

<one-to-one name="summary"
class="Summary"
cascade="all"
outer-join="true"
constrained="true" />

</class>


<class name="Summary"
table="SUMMARY"
dynamic-update="false"
dynamic-insert="false" >


<id name="id"
column="DOC_ID"
type="java.lang.Long"
unsaved-value="null" >

<generator class="foreign">
<param name="property">TxPurchaseOrder</param>
</generator>
</id>


<property name="Text"
type="java.lang.String"
update="true"
insert="true"
column="ORG_NAME" />

</class>
</hibernate-mapping>


In my code I want to ....

Session session = ... Session.Factory();

Document document = new Document();
.. Populate Document

Summary summary = new Summary();
.. Populate Summary

document.setSummary(summary);

session.save(document);


I find end up with a

[java] Hibernate: select DOC_SEQ.nextval from dual
[java] (business.Document ? ) unmapped property: Document
[java] hibernate.DAOException: unmapped property: Document wraps: [net.sf.hibernate.HibernateException: unmapped property: Document]
[java] at hibernate.BaseDAO.storeObj(Unknown Source)
[java] at domain.DocumentDAO.saveDocument(Unknown Source)


HAVA I JUST LOST THE PLOT ?

Cheers

Jon K


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 06, 2003 5:57 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Your mapping file should declare the class fullname

If your class full name is business.Document, the piece of mapping is

Code:
<class name="business.Document"
table="DOCUMENT"


Top
 Profile  
 
 Post subject: I made it too simple ....
PostPosted: Mon Oct 06, 2003 11:11 pm 
Newbie

Joined: Mon Oct 06, 2003 5:35 am
Posts: 9
Location: Perth.au
Hi,

Thanks for the reply, I simplified my code for the Forum and added errors. I would like to know if there is any definitive documentation on one-to-one mapping for Hibernate 2.0 ?

I want to model a Purchase Order which has a number of one-to-one mappings and one-to-many. The one to many work but I am having trouble with the one-to-one....

Ideally, I want to add one-to-one child objects to the Purchase Order and have it save with the Purchase Order using the Purchase Order's primary key as the child's primary key.

I am also using xdoclet to generate the hbm files.

For my Purchase Order : -

The class : -

<class
name="au.com.alphawest.po.domain.document.TxPurchaseOrder"
table="TX_PURCHASE_ORDER"
dynamic-update="false"
dynamic-insert="false" >

If Primary Key :-

<id name="id"
column="PO_ID"
type="java.lang.Long"
unsaved-value="null" >
<generator class="sequence">
<param name="sequence">TX_PO_SEQ</param>
</generator>
</id>

Using an Oracle sequence, the un-save value is null - as required

The mapping: -

<one-to-one
name="txPoBuyingParty"
class="au.com.alphawest.po.domain.document.TxPoBuyingParty"
cascade="all"
outer-join="true"
constrained="true" />

I want to save a Purchase Order and automatically save associated objects so cascade is true, the PO might not have a Buying Party so outer join is true and I want the Buying Party to use PO-ID as a foreign key so the releationship is constrained.


The Buying Party is :-

<class
name="au.com.alphawest.po.domain.document.TxPoBuyingParty"
table="TX_PO_BUYING_PARTY"
dynamic-update="false"
dynamic-insert="false"
>

The primary Key is: -

<id name="id"
column="PO_ID"
type="java.lang.Long"
unsaved-value="null" >
<generator class="foreign">
<param name="property">TxPurchaseOrder</param>
</generator>
</id>


I do not want bi-directional mapping but for now I have in the child : -

<one-to-one
name="txPurchaseOrder"
class="au.com.alphawest.po.domain.document.TxPurchaseOrder"
cascade="none"
outer-join="auto"
constrained="false"
/>

The database is create with: -

create table TX_PO_BUYING_PARTY (
[java] PO_ID NUMBER(19,0) not null,
[java] ORG_NAME VARCHAR2(255),
[java] ORG_SHORTNAME VARCHAR2(255),
[java] ORG_GUID VARCHAR2(255),
[java] ORG_ADDRESS_LINE1 VARCHAR2(255),
[java] ORG_ADDRESS_LINE2 VARCHAR2(255),
[java] ORG_SUBURB VARCHAR2(255),
[java] ORG_STATE VARCHAR2(255),
[java] ORG_POST_CODE VARCHAR2(255),
[java] ORG_COUNTRY VARCHAR2(255),
[java] CONTACT_FIRST_NAME VARCHAR2(255),
[java] CONTACT_FAMILY_NAME VARCHAR2(255),
[java] CONTACT_EMAIL VARCHAR2(255),
[java] CONTACT_PHONENO VARCHAR2(255),
[java] CONTACT_ADDRESS_LINE1 VARCHAR2(255),
[java] CONTACT_ADDRESS_LINE2 VARCHAR2(255),
[java] CONTACT_SUBURB VARCHAR2(255),
[java] CONTACT_STATE VARCHAR2(255),
[java] CONTACT_POST_CODE VARCHAR2(255),
[java] CONTACT_COUNTRY VARCHAR2(255),
[java] primary key (PO_ID)
[java] )


AND

[java] alter table TX_PURCHASE_ORDER add constraint FK8092ED8B48CAF5B foreign key (PO_ID) references TX_PO_BUYING_PARTY

If I add just data to the purchase order I get: -


[java] Hibernate: select TX_PO_SEQ.nextval from dual
[java] Hibernate: insert into TRADER.TX_PURCHASE_ORDER (STATE_ID, TRANSMISSION_DATE_TIME, ORDER_NUMBER, ORDER_DATE, PO_TYPE, CONTRACT_TITLE, CONTRACT_NUMBER, PO_RELEASE_NUMBER, ORDER_REQUEST_DATE, REQUESTED_DELIVERY_DATE, ORDER_REQUEST_REFERENCE, CURRENCY_CODE, SHIPPING_REQUIREMENT, TOTAL_TAXES, TOTAL_SHIPPING, TOTAL_MERCHANDISE, TOTAL_ALLOWANCES, TOTAL_LINE_ITEMS, TOTAL_AMOUNT, BUYER_ORG_GUID, BUYER_ORG_NAME, BUYER_ORG_UNIT_GUID, BUYER_ORG_UNIT_NAME, OWNER_GUID, OWNER_NAME, CREATOR_GUID, TRACKING_ID, PAYMENT_METHOD, PAYMENT_DETAILS, PAYMENT_TERMS, MIGRATE, PO_ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
[java] (util.JDBCExceptionReporter 38 ) SQL Error: 2291, SQLState: 23000
[java] (util.JDBCExceptionReporter 46 ) ORA-02291: integrity constraint (TRADER.FK8092ED8B48CAF5B7DDC2A21) violated - parent key not found

[java] (util.JDBCExceptionReporter 38 ) could not insert: [au.com.alphawest.po.domain.document.TxPurchaseOrder#1]
[java] java.sql.SQLException: ORA-02291: integrity constraint (TRADER.FK8092ED8B48CAF5B7DDC2A21) violated - parent key not found


The key is from another one-to-one mapping done the same as the BUYING_PARTY.


If I add all child objects I get: -

[java] Hibernate: select TX_PO_SEQ.nextval from dual
[java] (hibernate.BaseDAO ? ) unmapped property: TxPurchaseOrder


Any clues on what I am doing wrong or do I have to stop trying to cascade a save and do each child object in turn ?

Thanks

Jon K


Top
 Profile  
 
 Post subject: Is this a bug ?
PostPosted: Mon Oct 06, 2003 11:36 pm 
Newbie

Joined: Mon Oct 06, 2003 5:35 am
Posts: 9
Location: Perth.au
I have taken another look and ...

ALTER TABLE TX_PURCHASE_ORDER ADD (
CONSTRAINT FK8092ED8B48CAF5B FOREIGN KEY (PO_ID)
REFERENCES TX_PO_BUYING_PARTY (PO_ID));

ALTER TABLE TX_PURCHASE_ORDER ADD (
CONSTRAINT FK8092ED8B48CAF5B4C42A26D FOREIGN KEY (PO_ID)
REFERENCES TX_PO_REQUISITIONING_PARTY (PO_ID));

ALTER TABLE TX_PURCHASE_ORDER ADD (
CONSTRAINT FK8092ED8B48CAF5B72F36869 FOREIGN KEY (PO_ID)
REFERENCES TX_PO_SELLING_PARTY (PO_ID));

ALTER TABLE TX_PURCHASE_ORDER ADD (
CONSTRAINT FK8092ED8B48CAF5B7DDC2A21 FOREIGN KEY (PO_ID)
REFERENCES TX_PO_SHIPPING (PO_ID));

ALTER TABLE TX_PURCHASE_ORDER ADD (
CONSTRAINT FK8092ED8B48CAF5BE59399D1 FOREIGN KEY (PO_ID)
REFERENCES TX_PO_BILL_TO_PARTY (PO_ID));

If TX_PURCHASE_ORDER is the parent and TX_PO_BUYING_PARTY .. are the children then should the constraints be the other way around ?

Is this in the was I have configured my mappings or is somehting wierd happening with the foreign keys in hibernate ?

Cheers

Jon K


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.