-->
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.  [ 7 posts ] 
Author Message
 Post subject: Middlegen generate one-to-many instead of one-to-one
PostPosted: Mon Oct 03, 2005 2:45 am 
Newbie

Joined: Tue Aug 30, 2005 12:30 am
Posts: 9
[b]Hibernate version:[/b] 3.0.5 middlegen 2.1

[b]Sql commands:[/b]
/*==============================================================*/
/* Table: PAPER */
/*==============================================================*/
create table PAPER (
ID numeric(9) not null,
TYPE numeric(9) not null,
PAPERDESC varchar(255) not null,
GRAMATUR float(9) not null,
PDIMENSION float(9) not null,
LDIMENSION float(9) not null,
ENTRYUSER varchar(25) not null,
constraint PK_PAPER primary key (ID)
)
go


/*==============================================================*/
/* Table: PAPERPRICE */
/*==============================================================*/
create table PAPERPRICE (
ID numeric(9) not null,
HARGARIMPLANO float(9) not null,
HARGAPLANO float(9) not null,
REMARKS varchar(255) not null,
constraint PK_PAPERPRICE primary key (ID)
)
go

[b]Mapping documents:[/b]
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin 2.2

http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->

<class
name="marketingSystem.Paper"
table="PAPER"
>

<id
name="id"
type="java.lang.Integer"
column="ID"
>

<generator class="increment" />
</id>

<property
name="paperdesc"
type="java.lang.String"
column="PAPERDESC"
not-null="true"
length="255"
/>
<property
name="gramatur"
type="float"
column="GRAMATUR"
not-null="true"
length="24"
/>
<property
name="pdimension"
type="float"
column="PDIMENSION"
not-null="true"
length="24"
/>
<property
name="ldimension"
type="float"
column="LDIMENSION"
not-null="true"
length="24"
/>

<!-- Associations -->

<!-- bi-directional one-to-many association to PaperPrice -->
<set
name="paperPrices"
lazy="true"
inverse="true"
cascade="none"
>
<key>
<column name="ID" />
</key>
<one-to-many
class="marketingSystem.PaperPrice"
/>
</set>
<!-- bi-directional many-to-one association to User -->
<many-to-one
name="user"
class="marketingSystem.User"
not-null="true"
>
<column name="ENTRYUSER" />
</many-to-one>
<!-- bi-directional many-to-one association to PaperType -->
<many-to-one
name="paperType"
class="marketingSystem.PaperType"
not-null="true"
>
<column name="TYPE" />
</many-to-one>

</class>
</hibernate-mapping>



<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin 2.2

http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->

<class
name="marketingSystem.PaperPrice"
table="PAPERPRICE"
>

<id
name="id"
type="java.lang.Long"
column="ID"
>

<generator class="assigned" />
</id>

<property
name="hargarimplano"
type="float"
column="HARGARIMPLANO"
not-null="true"
length="24"
/>
<property
name="hargaplano"
type="float"
column="HARGAPLANO"
not-null="true"
length="24"
/>
<property
name="remarks"
type="java.lang.String"
column="REMARKS"
not-null="true"
length="255"
/>

<!-- Associations -->

<!-- bi-directional one-to-many association to PaperPriceHistory -->
<set
name="paperPriceHistories"
lazy="true"
inverse="true"
cascade="none"
>
<key>
<column name="PAPERPRICEID" />
</key>
<one-to-many
class="marketingSystem.PaperPriceHistory"
/>
</set>

</class>
</hibernate-mapping>



[b]Question:[/b]
I generate my hibernate xml using middlegen 2.1, the relation on database is one to one, but middlegen generated it one-to-many for me, any body can help me on this? i tried oracle9i and sqlserver, it generate me the same relationship.
thank you


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 03, 2005 2:47 am 
Newbie

Joined: Tue Aug 30, 2005 12:30 am
Posts: 9
sorry, here is the constraint
alter table PAPERPRICE
add constraint FK_PAPERPRI_REFERENCE_PAPER foreign key (ID)
references PAPER (ID)
go
thank you


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 03, 2005 7:32 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Did the GUI show the relationship as a one-to-one ?
[It should have - just wanted to check].

If it did not then remove the multiplicity from the many end and regenerate.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 03, 2005 11:26 pm 
Newbie

Joined: Tue Aug 30, 2005 12:30 am
Posts: 9
thanks for the reply
the gui show one-to-many relationship, in my sql server diagram show one to one relationship, i change the cardinality is show me :
Cardinality
Can't change the cardinality of a one-to-one relationship where the foreign key is also a primary key
any idea ?
thank you


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 04, 2005 2:16 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Sounds like a bug in the Middlegen core has crept in.
It should be showing it as a one-to-one so that the correct relationship values in the model are present for the generator to work correctly.

Create a Bug report in SourceForge for this.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 04, 2005 4:15 am 
Newbie

Joined: Tue Aug 30, 2005 12:30 am
Posts: 9
i has deleted my distr_kx-prefs.properties file with
relations.PAPER-PAPERPRICE.PAPER-has-PAPERPRICE.enabled=true
relations.PAPER-PAPERPRICE.PAPER-has-PAPERPRICE.target-many=false
relations.PAPER-PAPERPRICE.PAPERPRICE-has-PAPER.enabled=true
relations.PAPER-PAPERPRICE.PAPERPRICE-has-PAPER.target-many=false
and regenerate it give me a right one-to-one relationship.
thank you


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 04, 2005 6:21 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
OK Understand - the model has changed. Anyway, glad you found the problem.


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