Dave Tolls wrote:Since I presume city_name is not the primary key on the City table then Hibernate would have nothing to key off, even if this were possible.
I'm not sure what you're going to gain by this?
If you only want a list of city names, say for display on the front end or for dispatch somewhere, then why not write a query that returns just that for a given country?
You could build up the List from the List<City> but that might have some overhead as Hibernate will then pull all the Cities from the DB, when all you really want is the names.
I don't want to go into too much detail but we need to allow the user to update this list as well and when it is updated store it back into the City table. So you are right I could write a query for the load from database to get this list of city_name Strings and set it onto the Country entity (I assume that is what you were saying), but how would hibernate then know how to store it back for an update?
Also, city_name is part of a composite key (along with country_code) for the City table. Each row in the city table can be uniquely identified through the country_code and city_name pairing. I was hoping those 2 together (which we have in the Country entity) would be sufficient to let Hibernate know how to store back this list of city_names.