-->
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.  [ 11 posts ] 
Author Message
 Post subject: Pb! with one to one relation
PostPosted: Wed May 18, 2005 9:50 am 
Newbie

Joined: Tue May 17, 2005 10:58 am
Posts: 5
Location: France
hello

I am trying to do a one to one relation between two tables.
The first one has an "assigned" generator for the <id> tag.
And the second a "foreign" generator.
Both tables shared the same primary key, in my case :Worder_extrulg

And the error is:
[code]Exception non g


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 18, 2005 10:37 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
After "resultat1.Lgextru=Lg1;"
Add "Lg1.Resultat = resultat1;"

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 18, 2005 11:08 am 
Newbie

Joined: Tue May 17, 2005 10:58 am
Posts: 5
Location: France
thanks for your help!

but i have always the same error. :-(
I have used your advice in my program like this:

Code:
ExtrusionResults resultat1 = new ExtrusionResults();
resultat1.Lgextru=Lg1;
Lg1.Resultat=resultat1;
resultat1.MoyDtf10=14.58;
session.Save(Lg1);         
session.Flush();
transaction.Commit();
session.Close();



note: my configuration : Nhibernate 0.8.0.2 + Mysql 4.1.8 +VS 1.1 +connector .Net 1.0.4


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 19, 2005 1:05 am 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
As simple as it sounds, I think there is an error here:


Code:
<one-to-one cascade ="all" name="Resultat" class="Cablerie.Mapping.ExtrusionResults,Cablerie" />


there is an extra space between "cascade" and "="

Code:
<one-to-one cascade="all" name="Resultat" class="Cablerie.Mapping.ExtrusionResults,Cablerie" />


this little error may be preventing the cascading of the property. Also, I would suggest enabling Log4net so you can see the SQL that is generated. That might give us a better clue.

-devon


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 19, 2005 4:12 am 
Newbie

Joined: Tue May 17, 2005 10:58 am
Posts: 5
Location: France
Hello!

Good Morning

I have the same error: "Could not synchronise database state with session".
And MySql.Data.MySqlException :#23000Cannot add or update a child row.

is my problem comes from Mysql?
i attach at this post my Mysql's scripts:

Table Extrusion:
Code:
CREATE TABLE Extrusion (
  Worder_extrulg varchar(15) NOT NULL,
  Conducteur_pr_core INT NULL,
  Num smallint unsigned,
  Num_bobinetor varchar(15),
  ......

  PRIMARY KEY (Worder_extrulg),
  Index (Worder_extrulg)
)
TYPE=InnoDB;



Table resultat:
Code:
CREATE TABLE resultat
(
Worder_extrulg varchar(15),
Diam_extf2m double,
Diam_extf1m double,
Diam_extc1m double,
Ovalityf2m double,
Ovalityc1m double,
Ovalityf1m double,
Rexcentm double,
PRIMARY KEY(Worder_extrulg),
index(Worder_extrulg)
)type=innodb;



Foreign key:
Code:
ALTER TABLE resultat ADD CONSTRAINT fk_index1 FOREIGN KEY(Worder_extrulg)  REFERENCES extrusion(Worder_extrulg);

ALTER TABLE extrusion ADD CONSTRAINT fk_index2 FOREIGN KEY(Worder_extrulg)  REFERENCES resultat(Worder_extrulg);


Thanks for your help!

Best regards,
Guillaume


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 19, 2005 10:29 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
I didn't notice that you used your "string" primary keys to create the <one-to-one> relationship. I am not sure if it can work (either because they are string or because primary keys cannot be used like this).

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 19, 2005 11:57 am 
Newbie

Joined: Tue May 17, 2005 10:58 am
Posts: 5
Location: France
hi!

I have changed my generator to an native's generator with a int type.
i have the error: Could not save object : #23000Cannot add or update a child row... :(

i would like to unserstand what is the best way to realize a relation like this ("<one to one> with Mysql").
Mysql didn't like maybe the relation 1:1 with the share of the same primary key.
:?:


thanks for your help

Guillaume


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 19, 2005 2:58 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
It seems to me you have circular foreign key constraints in there :) leave only one of them, otherwise MySQL won't let you insert any row at all in the tables.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 20, 2005 12:32 am 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
I haven't used MySQL in quite some time, however, I am currently using a PK-> PKFK relationship in MSSQL for polymorphic associations and it works fine. Also, I have in the past used "String" objects as the primary key / NHibernate id without problem-- again in MSSQL.

Have you tried to insert your data into the MySQL database using the isql app? That would uncover any problems you might have in your datamodel.

-devon


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 20, 2005 3:52 am 
Hello everybody!

i have some questions for you.
I have used to realize my database the Merise's Model.
And in this model we can see that the relation 1:1 between two tables is made by the methods like this:

first one :

table A:

id_A (pK)
id_BFK)

table B:

id_B(PK)
id_A(FK)

the second :

table A:

id_A(PK,FK)

table B

id_A(PK,FK)

As NHibernate needs to use the same primary key between the two tables.
it's the reason why i have choosen the second method.
And i don't understand why i should use a polymorphic (in fact 1:n relation in Merise's Model) association to realize the one to one Nhibernate's relation.

I apply your advices and use the polymorphic association (PK--->PKfk),with the same Primary key on both tables.
But i have the same problem, could not synchronize database state with session.


Thank you very much for your help

have a good day :lol:

Guillaume


Top
  
 
 Post subject:
PostPosted: Fri May 20, 2005 4:23 am 
Newbie

Joined: Tue May 17, 2005 10:58 am
Posts: 5
Location: France
Thanks a lot!
:D
the relation <one to one > works fine with the PK-->PKFK relation. 8)
The problem is the position of the function Save.
We should save First, and Flush then.
But not at the end of the transaction.
could you explain that ?
Furthermore I have already teh same question.
Why i use in fact a 1:n relation in merise Model to realize in Nhibernate a 1:1 relation?

If you are an idea? :?:

Thank you very much kpixel,Sergey and DevonI!!!!!

My source if people is interested....


namespace Cablerie.Mapping
{
public class foreign
{

public foreign()
{

}
public void initialisation()
{

Configuration cfg = new Configuration();
cfg.AddAssembly("Cablerie");
ISessionFactory factory = cfg.BuildSessionFactory();
ISession session = factory.OpenSession();
ITransaction transaction = session.BeginTransaction();

try
{

LongueurExtrusion Lg1 = new LongueurExtrusion();
Lg1.Wextru = "BBBBBB/BB";
Lg1.NumeroBobine="BBBBBB32";
Lg1.PressionCaterpillar=12.58;
Lg1.TensionEnrouleurExterne=154.28;
Lg1.FeuillePrereglage="78-kl";
Lg1.BoiteVitesseCabestan=2500.50;
Lg1.BoiteVitesseDerouleur=150.24;
Lg1.BoiteVitesseEnrouleurMachine=458.12;
Lg1.Core="7-46ZV";
Lg1.DiametreExtrusionP1=11.4;
Lg1.DiametreExtrusionP2Chaud=6.25;
Lg1.DiametreExtrusionP2Froid=7.58;
//Save FIRST

session.Save(Lg1);

ExtrusionResults resultat1 = new ExtrusionResults();

resultat1.Lgextru=Lg1;
Lg1.Resultat=resultat1;
resultat1.MoyDtf10=14.58;

//Flush
session.Flush();
}
finally
{
transaction.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.  [ 11 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.