Well you map the same columns twice in the mapping file. You don't go into specifics, so I can only guess here, but I assume you get errors to that effect.
The <natural-id/> here is completely useless. <natural-id/> is really only useful in two scenarios:
1) When using Hibernate's schema generation capabilities to ensure appropriate constraints. But you state this is a pre-existing schema...
2) when using select-style generators. Hibernate can them use those <natural-id/> columns to uniquely identifiy rows to see the value generated for the PK column(s).
Basically, <natural-id/> is an optional mapping element. Either <id/> or <composite-id/> is required.
Again, you are being sort-of vague so it is difficult to help you. You say that you tried mapping this without the <natural-id/> stuff but ran into problems with that. Well what were those problems? That is the correct way to do it.
Quote:
And I don't fully understand the caveat in the manual in section 6.1.5, "Unfortunately, this approach to composite identifiers means that a persistent object is its own identifier. There is no convenient 'handle' other than the object itself. You must instantiate an instance of the persistent class itself and populate its identifier properties before you can load() the persistent state associated with a composite key." What does that mean to me in terms of how I must code to use this approach?
Well, without a seperate "PK class", the individual properties making up the PK are mapped to the entity class itself. In your case, that means ServiceProvider would have the properties for name and location. Thus, think about what it take to load a ServiceProvider instance in that case. Basically, the code would look like:
Code:
ServiceProvider sp = new ServiceProvider();
sp.setName( "someName" );
sp.setLocation( "someLocation" );
sp = ( ServiceProvider ) session.load( ServiceProvider.class, sp );
Ugly, right? Much nicer mapping this using a seperate class encapsulating the PK fields. Something like:
Code:
ServiceProviderPK pk = new ServiceProviderPK( "someName", "someLocation" );
ServiceProvider sp = ( ServiceProvider ) session.load( ServiceProvider.class, pk );