I am having trouble understand what I thought would be a simple mapping, but there is something I am missing. I have tried to simplify this example as much as possible to get to the core of it.
I have a Country class,
Code:
public class Country {
private long id;
private String code;
private String name;
// getters and setters
...
}
and an Address class
Code:
{
public class Address {
private long id;
private String state;
private Country country;
// getters and setters
...
}
The database schema for these classes is like so:
Code:
Table: Addresses
id
state
countryId
Code:
Table: Countries
id
code
name
So what mapping strategy should be used to make this relationship in the sense that when I load an Address from the database, the country object is populated with a join from the countries table, but also, and this is the part that confuses me most, when I save an Address, I don't want the countries table to try to be updated, but rather just the countryId in the Addresses table (that matches the ID in the country object)