I would like to perform a mapping between an object that contains a collection of files, called Package, and a collection of file objects, call PackageFile. I do not want to use the primary keys for this mapping. Instead I want to use the GUIDs from the object to form the relationship. When I run my test, I get an empty result set.
The reason I'm looking to do this is because these objects are being transferred over a web service, and the guid & guid relationships must remain in tact. However since they are coming across via the web service, they must be INSERTed on the receiving end preferrably using Hibernate's cascade functionality. So I blow away the IDs, keep the GUIDs, and everything inserts as it should.
On the Package side, I have the following snippet in my mapping doc:
Code:
<set name="packageFiles" inverse="true" >
<key column="package_guid" foreign-key="guid" />
<one-to-many class="PackageFile"/>
</set>
... and on the PackageFile side, I have the following snippet:
Code:
<many-to-one name="aPackage" class="Package" column="package_guid" property-ref="guid" />
So what I would expect would happen is my set of package files would be mapped using Package.guid = FilePackage.package_guid. Hibernate is using the package_guid column from the collection table, but I can see where it's binding a '1' to the query parameter, which means the package id value is being used instead of the package guid value. So in the end, I get:
X 3015 DEBUG [main] net.sf.hibernate.type.LongType - binding '1' to parameter: 1
X 3031 DEBUG [main] net.sf.hibernate.loader.Loader - result set contains (possibly empty) collection: [com.teksouth.jswift.core.domain.Package.packageFiles#1]
X 3031 DEBUG [main] net.sf.hibernate.impl.SessionImpl - uninitialized collection: initializing[code]