If I were to have the following object model:
Code:
public class Foo {
String id;
String description;
List<FooVersion> versions;
// Constructors, getters, setters, etc.
}
public class FooVersion {
int id;
String fooId;
String description;
// Constructors, getters, setters, etc.
}
So, in the database, there is a one-to-many relationship between Foo and FooVersions. Let's say I had an instance of Foo with three FooVersions. I make a change to Foo itself and add a new FooVersion.
Code:
// Change foo
Foo foo = (Foo) session.load(Foo.class, someFooId);
foo.setDescription(foo.getDescription().concat(" now with more awesome"));
// Add a new version, let's assume the id will be generated by the database -- there should be 4 FooVersions now associated with this Foo object
FooVersion newVersion = new FooVersion(foo.getId(), "More Awesomer Version");
foo.getVersions().add(newVersion);
session.saveOrUpdate(foo, foo.getId());
Does the new FooVersion get added or do I need to add that explicitly? Should I be calling Session.update() instead of letting Hibernate guess? Is this dependent on the mapping?
Thanks!