-->
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: hibernate3 hbm2ddl adding unwanted foreign key constraints
PostPosted: Wed May 25, 2005 12:51 am 
Newbie

Joined: Tue Feb 08, 2005 4:16 am
Posts: 14
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hi!!

I am upgrading a large project to use hibernate3 (woeked with hibernate-2.1.7).

I have an any-mapping in my project that looks like that:

<any name="parent" meta-type="string" id-type="long" cascade="save-update" >
<meta-value value="com.mercury.dashboard.model.module.Module" class="com.mercury.dashboard.model.module.Module"/>

<meta-value value="com.mercury.dashboard.model.portletdef.PortletDefinition" class="com.mercury.dashboard.model.portletdef.PortletDefinition"/>
...

<column name="PARENT_ENTITY_NAME" not-null="true" length="200" unique="false" />
<column name="PARENT_PRIMARY_KEY" not-null="true" unique="false" />
</any>

The mapping on the other side (in Module and PortletDefinition xml's) look like that:
<set
name="authorizedUsers"
table="DSH_AUTHORIZED_USERS"
lazy="true"
inverse="true"
cascade="all"
sort="unsorted"
where="parent_entity_name = 'com.mercury.dashboard.model.module.Module'"
>

<key
>
<column name="PARENT_PRIMARY_KEY"/>
</key>

<one-to-many
class="com.mercury.dashboard.model.access.AuthorizedUser"
/>

</set>

and a similar thing for PortletDefinition...

Now, the problem is that schemaexport creates TWO different foreign key constrains on the same table and on the same column that make it impossible to add entries to this table - these are the created constraints:
alter table DSH_AUTHORIZED_USERS add constraint FK48AC982AE790DD7E foreign key (PARENT_PRIMARY_KEY) references DSH_PORTLET_DEFS;
alter table DSH_AUTHORIZED_USERS add constraint FK48AC982AB130BA34 foreign key (PARENT_PRIMARY_KEY) references DSH_MODULES;

Is it possible to ommit these constraints somehow? BTW, the old version did not add these foreign key constraints!!!

Thanks

Hibernate version:
hibernate-3.0.4


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 29, 2005 2:46 am 
Newbie

Joined: Tue Feb 08, 2005 4:16 am
Posts: 14
OK.

After some debugging of new code for hbm2ddl I got the answe - hope this helps to others:

you should add foreign-key="none" as an attribute to the <key> tag:

<set
name="authorizedUsers"
table="DSH_AUTHORIZED_USERS"
lazy="true"
inverse="true"
cascade="all"
sort="unsorted"
where="parent_entity_name = 'com.mercury.dashboard.model.module.Module'"
>

<key foreign-key="none"
>
<column name="PARENT_PRIMARY_KEY"/>
</key>

<one-to-many
class="com.mercury.dashboard.model.access.AuthorizedUser"
/>

Enjoy


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 28, 2005 11:24 am 
Newbie

Joined: Thu Feb 17, 2005 5:19 am
Posts: 8
Thanks, I had a similar problem, and that was the solution! :-)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 18, 2005 6:22 am 
Newbie

Joined: Tue Feb 08, 2005 4:16 am
Posts: 14
I am glad it helped. You are welcome.


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.