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: Adding array values to database outside of wrapping object
PostPosted: Tue Jun 08, 2004 8:31 pm 
Newbie

Joined: Tue Jun 08, 2004 8:07 pm
Posts: 14
Location: Washington, D.C.
Hibernate 2.1.2

I am trying to use hibernate for mapping UDDI types to a database. I object model is a little unique in that UDDI Services can be added to a Business just by having a the key of that business (which is a string).

So here is my problem. Is it possible to update an array outside of the enclosing object (i.e. just update the array index column to update the index value with the correct value, instead of inserting null)?

Let me try to make this more clear:

Configuration configuration = new Configuration();
configuration.addFile( "C:\\business.hbm.xml" );
configuration.addFile( "C:\\service.hbm.xml" );
SessionFactory factory = configuration.buildSessionFactory();
Session session = factory.openSession();

Business business = new electric.uddi.Business();
String businessKey = "bKey";
business.setBusinessKey( businessKey );

Service service = new Service();
service.setBusinessKey( businessKey );
String serviceKey = "sKey";
service.setServiceKey( serviceKey );

session.save( business, businessKey );
session.save( service, serviceKey );

This works great; later, however, I'd like to be able to save another service associated with the same business key using a different session;

Service service2 = new Service();
service.setBusinessKey( "bKey" );
String serviceKey = "sKey2";
service2.setServiceKey( serviceKey );

Session differentSession= factory.openSession();
differentSession.save( service2, serviceKey );

Here is some debug info that my explain it better... after saving the Business and service in the first session I see:

20:15:00,266 DEBUG SQL:237 - insert into businesses (name, operator, authorizedName, business_key) values (?, ?, ?, ?)
20:15:00,316 DEBUG SQL:237 - insert into services (name, userName, business_key, service_key) values (?, ?, ?, ?)
20:15:00,316 DEBUG SQL:237 - update services set business_key=?, array_index=? where service_key=?
20:15:00,336 DEBUG SQL:237 - insert into descriptions (description_key, description_index, text, language) values (?, ?, ?, ?)

One the ensuing second save with the new session where I am only saving the service associated with the first business key I see:

20:16:09,695 DEBUG SQL:237 - insert into services (name, userName, business_key, service_key) values (?, ?, ?, ?)
20:16:09,715 DEBUG SQL:237 - insert into descriptions (description_key, description_index, text, language) values (?, ?, ?, ?)

Ideally I would also see the update call after the insert into services.

Below are my two mapping files. Any help would be greatly appreciated.

~harris

p.s. hope these xml files are too jumbled up!! :-)

<!-- service.hbm.xml -->
<hibernate-mapping>
<class name="electric.uddi.Service" table="services">
<id name="serviceKey" type="string" column="service_key">
<generator class="assigned"/>
</id>
<property name="name" column="name" type="string"/>
<property name="userName" column="userName" type="string"/>
<!-- <many-to-one name="businessKey" class="electric.uddi.Business" column="business_key" cascade="save-update" /> -->
<property name="businessKey" column="business_key" type="string"/>
<array name="descriptions" table="descriptions">
<key column="description_key" foreign-key="service_key"/>
<index column="description_index"/>
<composite-element class="electric.uddi.Description">
<property name="text" column="text" type="string"/>
<property name="language" column="language" type="string"/>
</composite-element>
</array>
</class>
</hibernate-mapping>


<!-- business.hbm.xml -->
<hibernate-mapping>
<class name="electric.uddi.Business" table="businesses">
<id name="businessKey" type="string" column="business_key">
<generator class="assigned"/>
</id>
<property name="name" column="name" type="string"/>
<property name="operator" column="operator" type="string"/>
<property name="authorizedName" column="authorizedName" type="string"/>
<array name="services" table="services" inverse="false" cascade="none">
<key column="business_key"/>
<index column="array_index"/>
<one-to-many class="electric.uddi.Service"/>
</array>
<array name="descriptions" table="descriptions">
<key column="description_key" foreign-key="business_key"/>
<index column="description_index"/>
<composite-element class="electric.uddi.Description">
<property name="text" column="text" type="string"/>
<property name="language" column="language" type="string"/>
</composite-element>
</array>
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 08, 2004 10:34 pm 
Newbie

Joined: Tue Jun 08, 2004 8:07 pm
Posts: 14
Location: Washington, D.C.
Problem solved...

I just need to call:

session.update on my Business object after inserting a new Service.

thanks for reading! :-)

~harris


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.