| I'm unable to get a successful result when using the methodology outlined in "Example 290. Bidirectional association". I setup a Product and a Store entity where Product is ManyToOne Store, and when I update the relationship from the Store entity like it shows in the documentation "store.getProducts().add(product)", it fails to update the product relationship. The same goes for remove. Below is my code and some examples of what does and doesn't work. And I'm citing from "Example 292. Correct normal Java usage" for my usage. public class Product { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private long id; @ManyToOne(cascade = CascadeType.ALL) private Store store; public long getId() { return id; } public Store getStore() { return store; } public Product setStore(Store store) { this.store = store; return this; } } public class Store { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private long id; @OneToMany(mappedBy = "store", cascade = CascadeType.ALL) private List<Product> products = new ArrayList<>(); public long getId() { return id; } public List<Product> getProducts() { return products; } public Store setProducts(List<Product> products) { this.products = products; return this; } } // Fails Store store = new Store(); Product product1 = new Product(); Product product2 = new Product(); store.getProducts().add(product1); store.getProducts().add(product2); // Works Store store = new Store(); Product product1 = new Product(); Product product2 = new Product(); List<Product> blah = store.getProducts(); blah.add(product1); blah.add(product2); store.setProducts(blah); // Works Store store = new Store(); Product product = new Product(); product.setStore(store); |