-->
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.  [ 28 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: one-to-one and <generator class="foreign"
PostPosted: Thu Nov 20, 2003 10:54 am 
Regular
Regular

Joined: Thu Nov 20, 2003 10:44 am
Posts: 58
Location: Paris, France
Dear all,
I've got the following situtation between 2 tables Edition and Index Edition with a one-to-one relation i.e the PK of Edition is also the PK of IndexEdition. The pb is that the PK of Index Edition is a sequence, therefore the data are inserted in IndexEdition but not in Edition.

Please HELP I become crazy !

The mapping is as follows :

<hibernate-mapping>
<class name="EditionPersistent" table="EDITION">
<id name="numEdition" column="PK_EDITION" unsaved-value="any">
<generator class="foreign"/>
</id>
......
</class>
</hibernate-mapping>

<hibernate-mapping>
<class name="IndexEditionPersistent" table="INDEX_EDITION">
<id name="numIndexEdition" column="PK_INDEX_EDITION">
<generator class="sequence">
<param name="sequence">S_INDEX_EDITION</param>
</generator>
....
<one-to-one name="edition" class="EditionPersistent" cascade="all" constrained="true"/>
</class>
</hibernate-mapping>

I've got the following message (error?) :
- reflection optimizer disabled for: EditionPersistent, NullPointerException: null


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 20, 2003 10:59 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Ah you actually need the class with the foreign generator to have an inverse <one-to-one> and mention that propety in a <param> tag. But actually, the side with the foreign generator needs to be the side with constrained="true" .... so I'm not so sure how well it works for you.


Check the Hibernate tests package for an example of correct usage.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 20, 2003 11:02 am 
Regular
Regular

Joined: Thu Nov 20, 2003 10:44 am
Posts: 58
Location: Paris, France
gavin wrote:
Ah you actually need the class with the foreign generator to have an inverse <one-to-one> and mention that propety in a <param> tag. But actually, the side with the foreign generator needs to be the side with constrained="true" .... so I'm not so sure how well it works for you.


Check the Hibernate tests package for an example of correct usage.


Actually it doesn't work at all !!!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 20, 2003 11:04 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
ummmm .... what do you mean?

yes, it works .... if you use it as intended....


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 20, 2003 11:06 am 
Regular
Regular

Joined: Thu Nov 20, 2003 10:44 am
Posts: 58
Location: Paris, France
gavin wrote:
ummmm .... what do you mean?

yes, it works .... if you use it as intended....


There's definitively a pb with the class="foreign" for the id and i can't find what the f... it is !


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 20, 2003 11:07 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Look at the examples in the test package.

I'm repeating myself here I think.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 20, 2003 11:13 am 
Regular
Regular

Joined: Thu Nov 20, 2003 10:44 am
Posts: 58
Location: Paris, France
gavin wrote:
Look at the examples in the test package.

I'm repeating myself here I think.


You are speaking about the example of the cat ?
Actually I should use a 'meet in the middle' method so I can't change anything, neither DB model not OM.
Moreover it works without any sequence if I assign the key but as soon as I had a sequence it doesn't work


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 20, 2003 11:18 am 
Senior
Senior

Joined: Tue Sep 23, 2003 8:18 am
Posts: 137
Location: Johannesburg, South Africa
To stop the to-and-fro...here's my example...and it works... :P

Code:
<class name="dse6.cdl.impl.XMLImpl" table="XML">
    <id name="XMLID" column="XMLID" type ="java.lang.Long" unsaved-value="null">
        <generator class="identity"/>
    </id>
...
    <one-to-one name="Matter" class="dse6.cdl.impl.MatterImpl" cascade="all"/>
</class>

and the other side:
Code:
<class name="dse6.cdl.impl.MatterImpl" table="Matter">
    <id name="XMLID" column="XMLID" type ="java.lang.Long" unsaved-value="null">
        <generator class="foreign">
            <param name="property">XML</param>
        </generator>
    </id>
...
    <one-to-one name="XML" class="dse6.cdl.impl.XMLImpl" constrained="true"/>
</class>

Modify yours to match that...and it should work. :)

-G


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 20, 2003 11:39 am 
Regular
Regular

Joined: Thu Nov 20, 2003 10:44 am
Posts: 58
Location: Paris, France
No it doesn't work :( ... exception : unmapped property. So let's see the code :

Java class :
Code:
public class EditionPersistent
{
   private int numEdition ;
   private byte[] document ;
   
   // .....
   // + getter and setter
}

public class IndexEditionPersistent
{
   //key
   private int numIndexEdition ;
   private EditionPersistent edition;
 
  // .....
  // + getter and setter
}


Table script
Code:

CREATE TABLE INDEX_EDITION (
   PK_INDEX_EDITION NUMBER ( 10 ) NOT NULL,  <-- SEQUENCE
   TYPE NUMBER ( 1 ) NOT NULL,
   CLE NUMBER ( 10 ) NOT NULL,
   DATE_CREATION DATE NOT NULL,
   CONSTRAINT PK_INDEX_EDITION_1 PRIMARY KEY (PK_INDEX_EDITION)
   );

CREATE TABLE EDITION (
   PK_EDITION NUMBER ( 10 ) NOT NULL,
   DOCUMENT BLOB NOT NULL,
   CONSTRAINT PK_EDITION_1 PRIMARY KEY (PK_EDITION)
   );
ALTER TABLE EDITION ADD ( CONSTRAINT FK_EDITION_1 FOREIGN KEY (PK_EDITION) REFERENCES INDEX_EDITION (PK_INDEX_EDITION));



Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 20, 2003 12:02 pm 
Senior
Senior

Joined: Tue Sep 23, 2003 8:18 am
Posts: 137
Location: Johannesburg, South Africa
Did you do as Gavin said and add in the <one-to-one> in the foreign class? Along with the constrained option?

Do you actually "create sequence S_INDEX_EDITION" ?

-G


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 20, 2003 12:05 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
If you can't change the OM and don't have a reverse one-to-one, so replace foreign with assigned and set it manually

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 20, 2003 12:18 pm 
Regular
Regular

Joined: Thu Nov 20, 2003 10:44 am
Posts: 58
Location: Paris, France
Brannor McThife wrote:
Did you do as Gavin said and add in the <one-to-one> in the foreign class? Along with the constrained option?

Do you actually "create sequence S_INDEX_EDITION" ?

-G


Yes I did


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 20, 2003 12:29 pm 
Regular
Regular

Joined: Thu Nov 20, 2003 10:44 am
Posts: 58
Location: Paris, France
epbernard wrote:
If you can't change the OM and don't have a reverse one-to-one, so replace foreign with assigned and set it manually


But I can't it is a sequence !!!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 20, 2003 1:14 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Try
Code:
IndexEditionPersistent idx = new IndexEditionPersistent();
//fill in
session.save(idx);
EditionPersistent ed = new EditionPersistent();
ed.setNumEdition(idx.getNumIndexEdition());
session.save(ed);

session.flush();


I'm not sure of me, though

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 20, 2003 1:19 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
yes, that would work.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 28 posts ]  Go to page 1, 2  Next

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.