Hello:
We are trying to model a set of classes that represent geographical locations. We have a set of GeoClasses that represent State,Countries, PostalCodes, and Cities. A Location class points to each of these classes using a many-to-one relationship, ie many locations will refer to a single Country record etc.
So Our location object looks something like
Location
{
address1,
address2,
address3,
geoCity,
geoState,
geoPostalCode,
geoCountry
}
The GeoPostalCode object is keyed by CountryCode (string) and (postal code) string.
We want to be able to create locations where only minimal information is nessisary, ie only a city name and country are given, or just perhaps a country.
The issue comes in on how to map the Postal Code and Country code. We want locations to not require a postal code but require a country.
So our latest attempt is as follows:
<many-to-one name="country" class="GeoCountry" column="country" not-null="true" >
</many-to-one>
<many-to-one name="postalCode" class="GeoPostalCode" insert="false" update="false" >
<column name="postal_code" />
<column name="country" />
</many-to-one>
This correctly allows us to generate the right SQL table, and insert locations with null postal codes, but with a correct Country.
Our Issue:
Upon trying to retrieve a location where the postalcode is null, Hibernate attempts to lazy load the postal code "null" using the country code in location record which results in an error since there is no record in the GeoPostalCode table that has a country of us with a code of null.
Any suggestions on how to configure the metadata to represent this situation where a compound key ie country and postal code share a common column ie country but where the country may be non-null, but postal code null.
Mike...
|