-->
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.  [ 3 posts ] 
Author Message
 Post subject: Newbie Persistence Mapping Problem
PostPosted: Mon Jun 04, 2007 1:43 pm 
Newbie

Joined: Mon Jun 04, 2007 1:25 pm
Posts: 2
Bit of a Hibernate newbie, having problem with some mappings persisting in the database.

We have three domain objects subscriber, ips and geodata. Updating these
via Hibernate and the three database tables are all persisted. Howoever, the relation between ips and geodata (geo_data_to_ips) is not persisted. No exceptions thrown or any error messages appearing in the log with Hibernate debug on. We do have very similar code that works fine. Now I'm probably doing something rather silly but can't spot what it is...

The relevant bits of the hibernate mappings are

<hibernate-mapping>
<class name="com.mediagraft.podsplice.domain.Subscriber" table="subscribers">
<cache usage="transactional" />
<id name="subscriberId" type="long" column="user_id">
<generator class="foreign">
<param name="property">user</param>
</generator>
</id>
<set name="ips" table="ips" lazy="true"
cascade="save-update,delete,delete-orphan" inverse="true">
<key column="ips_id"/>
<one-to-many class="com.mediagraft.podsplice.domain.Ip"/>
</set>
</class>
</hibernate-mapping>

<hibernate-mapping>
<class name="com.mediagraft.podsplice.domain.Ip" table="ips">
<cache usage="transactional" />
<id name="id" type="long">
<column name="ips_id"/>
<generator class="sequence">
<param name="sequence">ips_id</param>
</generator>
</id>
<many-to-one name="subscriber"
column="user_id"
not-null="true"
class ="com.mediagraft.podsplice.domain.Subscriber"/>
<property name="ip" type="string">
<column name="ip"/>
</property>
<property name="ipDate" type="calendar">
<column name="ip_date"/>
</property>
<join table="geo_data_to_ips" inverse="true" optional="true">
<key column="ips_id"/>
<many-to-one name="geoData"
column="geo_data_id"
not-null="true"
cascade="save-update, delete"
class ="com.mediagraft.podsplice.domain.GeoData"/>
</join>
</class>
</hibernate-mapping>

<hibernate-mapping>
<class name="com.mediagraft.podsplice.domain.GeoData" table="geo_data">
<cache usage="transactional" />
<id name="id" type="long">
<column name="geo_data_id"/>
<generator class="sequence">
<param name="sequence">geo_data_id</param>
</generator>
</id>
<property name="countryCode" type="string">
<column name="country_code"/>
</property>

<set name="ips" table="geo_data_to_ips" lazy="true"
cascade="save-update,delete,delete-orphan" inverse="true">
<cache usage="transactional" />

<key column="geo_data_id"/>
<many-to-many class="com.mediagraft.podsplice.domain.Ip" unique="true" column="ips_id"/>
</set>
</class>
</hibernate-mapping>

and the postgres schema for the tables

CREATE TABLE subscribers
(
user_id int8 NOT NULL,
CONSTRAINT subscribers_pkey PRIMARY KEY (user_id),
CONSTRAINT subscribers_fkey_userid FOREIGN KEY (user_id)
REFERENCES users (user_id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE CASCADE
)

CREATE TABLE ips
(
ips_id int8 NOT NULL,
user_id int8 NOT NULL,
ip varchar(15) NOT NULL,
ip_date timestamp NOT NULL,
CONSTRAINT ips_pkey PRIMARY KEY (ips_id),
CONSTRAINT ips_fkey_user_id FOREIGN KEY (user_id)
REFERENCES subscribers (user_id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE CASCADE
)



CREATE TABLE geo_data
(
geo_data_id int8 NOT NULL,
country_code varchar(2) NOT NULL,
CONSTRAINT geo_data_pkey PRIMARY KEY (geo_data_id),
CONSTRAINT geo_data_country_code_key UNIQUE (country_code)
)


Thanks,
Mike


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 05, 2007 12:22 am 
Senior
Senior

Joined: Sat Aug 19, 2006 6:31 pm
Posts: 139
It seems like both mapping files (Ip and GeoData) have the inverse set to "true" for its mapping to geo_data_to_ips table.

One of them needs to be the owner of the relationship and have inverse set to false (or not specified).

Code:
<join table="geo_data_to_ips" inverse="true" optional="true">


Code:
<set name="ips" table="geo_data_to_ips" lazy="true"
cascade="save-update,delete,delete-orphan" inverse="true">

_________________
Don't forget to rate the reply if it helps..:)

Budyanto


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 05, 2007 4:50 am 
Newbie

Joined: Mon Jun 04, 2007 1:25 pm
Posts: 2
Thanks that that pointed in the right direction. Deleting the cascade="save-update,delete,delete-orphan" inverse="true" on the geodata mapping fixed the problem.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.