-->
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.  [ 2 posts ] 
Author Message
 Post subject: How can i update foreign key?
PostPosted: Wed Jun 25, 2008 8:45 am 
Newbie

Joined: Wed Jun 25, 2008 3:47 am
Posts: 1
Hi,

How can i update foreign key (CITY) in TableA without updating TableB?
Anybody help me?

My classes and mappings as flow;

I have tow classes like as A and B. Tables are

Create TableA (HOTSPOT_ID(PK),..., CITY(FK for Table B))
Create TableB (CITY(PK),....)

Association is many-to-one


class A
{

B b;
..getB
..setB
}

class B
{
.....
}

and my A.hibernate.xml

<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class
name="com.gantek.model.HotspotNew"
table="HOTSPOT_TEMP"
dynamic-update="false"
dynamic-insert="false"
>

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

>
<generator class="foreign">
<param name="property">hotspotAdt</param>
</generator>

</id>


<property
name="customerID"
type="java.lang.Integer"
update="true"
insert="true"
access="property"
column="CUSTOMER_ID"
not-null="false"
/>

<property
name="nasIp"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="NAS_IP"
length="15"
not-null="true"
/>

<property
name="definition"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="DEFINITION"
length="50"
not-null="true"
/>
<property
name="active"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="active"
not-null="false"
/>

<many-to-one name="city" class="com.gantek.model.Cities"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="property"
column="CITY"
not-null="true"
/>

<many-to-one
name="hotspotType"
class="com.gantek.model.HotspotType"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="property"
column="HOTSPOT_TYPE"
/>

<many-to-one
name="hotspotType2"
class="com.gantek.model.HotspotType2"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="property"
column="HOTSPOT_TYPE2"

/>

<one-to-one name="hotspotAdt" class="com.gantek.model.HotspotAdt" constrained="true" cascade="all"/>




</class>

</hibernate-mapping>



B.hibernate.xml



<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class
name="com.gantek.model.Cities"
table="system_cities"
dynamic-update="false"
dynamic-insert="false"
>

<id
name="ID"
column="city_id"
type="java.lang.Long"
unsaved-value="null"
>
<generator class="assigned">
</generator>
</id>

<property
name="DESCRIPTION"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="description"
length="128"
/>
</class>

</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 25, 2008 10:31 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Your object has an association to another object, which is essentially the object oriented realization of the foreign key. Just load a new object from the foreign talbe, and associate that object with the associating object. Do a save, and the foreign key mapping will have changed.

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


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