0
我對hibernate頗爲陌生。我創建了兩個用戶和車輛實體,用戶與車輛有一對多的關係。無法在休眠狀態下創建一對多映射表
@OneToMany
@JoinColumn(name="Vehicle_id")
Collection<Vehicle> vehicle = new ArrayList<>();
,並把它們添加到表像這樣
UserInfo user = new UserInfo();
user.setUsername(username);
user.setPassword(password);
user.setDob(dob);
Vehicle vehicle = new Vehicle();
vehicle.setVehicleName("AUdi");
user.getVehicle().add(vehicle);
Vehicle vehicle2 = new Vehicle();
vehicle2.setVehicleName("BMW");
user.getVehicle().add(vehicle2);
SessionFactory sessionfactory = new AnnotationConfiguration().configure().buildSessionFactory();
Session session = sessionfactory.openSession();
session.beginTransaction();
session.save(user);
session.save(vehicle);
session.save(vehicle2);
session.getTransaction().commit();
session.close();
但我得到的結果一樣
Hibernate: insert into UserInformation (user_name, DOB) values (?, ?)
Hibernate: insert into Vehicle (vehicleName) values (?)
Hibernate: insert into Vehicle (vehicleName) values (?)
Hibernate: update Vehicle set Vehicle_id=? where vehicleID=?
Hibernate: update Vehicle set Vehicle_id=? where vehicleID=?
沒有像
insert into User_vehicle(User_id,vehicle_id) Values (?,?)
所以我創建的表沒有得到任何表名分貝中的。
希望你能理解我的問題。
謝謝德拉甘B.它先生現在工作正常。 –