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>
|