hereからチュートリアルに従っていますが、理解できない部分があります。
4. 実行 – ケース1
session.beginTransaction(); 在庫在庫 = new Stock(); stock.setStockCode("7052"); stock.setStockName("PADINI"); Category category1 = new Category("消費者", "消費者企業"); session.save(カテゴリ1); StockCategory stockCategory = 新しい StockCategory(); stockCategory.setStock(株式); stockCategory.setCategory(カテゴリ1); stockCategory.setCreatedDate(新しい日付()); //余分な列 stockCategory.setCreatedBy("システム"); //余分な列 stock.getStockCategories().add(stockCategory); session.save(在庫); session.getTransaction().commit();
在庫とカテゴリ 1 の間の関連付けが作成されました。
stockCategory.setStock(株式); stockCategory.setCategory(カテゴリ1);
では、なぜまだ必要なのか
stock.getStockCategories().add(stockCategory);
ありがとう!!