我正在尝试解决tutorial,最后我注意到在运行主类时:
public class App {
public static void main(String[] args) {
System.out.println("Hibernate one to many (Annotation)");
Session session = HibernateUtil.getSessionFactory().openSession();
session.beginTransaction();
Stock stock = new Stock();
stock.setStockCode("7052");
stock.setStockName("PADINI");
session.save(stock);
StockDailyRecord stockDailyRecords = new StockDailyRecord();
stockDailyRecords.setPriceOpen(new Float("1.2"));
stockDailyRecords.setPriceClose(new Float("1.1"));
stockDailyRecords.setPriceChange(new Float("10.0"));
stockDailyRecords.setVolume(3000000L);
stockDailyRecords.setDate(new Date());
stockDailyRecords.setStock(stock);
stock.getStockDailyRecords().add(stockDailyRecords);
session.save(stockDailyRecords);
session.getTransaction().commit();
System.out.println("Done");
}
在这一行,
stock.getStockDailyRecords().add(stockDailyRecords);
我无法理解它有用的是什么?我试图删除它,但它插入行没有任何问题,那么它的用途是什么?为什么他没有使用setDailyRecords(stockDailyRecords)
代替,是否有一些我不理解的东西?