I'm not sure but I think it is not doable.
If you will be returning new Location from getter (in the case actual location is null), or you will be substitute Location in setter (in the case parameter is null), sooner or later Hibernate will attempt to save your object to the database because from Hibernate's point of view there was a change - Location was null and it is not null anymore. This is because Hibernate uses the same getter as your code to obtain location.
Theoretically, if you tell Hibernate to use direct access to the location field (do not use getter/setter) and provide getter like
Code:
public Location getLocation()
{
return (location != null) ? location : new Location;
}
it will solve your particular problem and will not cause Hibernate to save transient locations. But this approach really sucks because each time you call getLocation you will be getting different objects. And you may forget about something like
Code:
obj.getLocation().setState("xxx");
To me it is better to check if returned location is null or not at every place neede.