【发布时间】:2014-05-21 14:39:41
【问题描述】:
可能是一个愚蠢的问题,但我不明白。 所以我有一个像这样的课程:
@Entity
@Table(name="colour"
,catalog="car_store"
)
public class Colour implements java.io.Serializable {
private Byte id;
private String name;
private Set<Car> cars = new HashSet<Car>(0);
public Colour() {
}
public Colour(String name) {
this.name = name;
}
public Colour(String name, Set<Car> cars) {
this.name = name;
this.cars = cars;
}
@Id @GeneratedValue(strategy=IDENTITY)
@Column(name="id", unique=true, nullable=false)
public Byte getId() {
return this.id;
}
public void setId(Byte id) {
this.id = id;
}
@Column(name="name", nullable=false)
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
@OneToMany(fetch=FetchType.LAZY, mappedBy="colour")
public Set<Car> getCars() {
return this.cars;
}
public void setCars(Set<Car> cars) {
this.cars = cars;
}
}
所以如果我想插入这样的:
Session session = HibernateUtil.getSessionFactory().openSession();
Colour newColour = new Colour();
newColour.setName("Deep Sea Blue");
session.save(newColour);
session.getTransaction().commit();
在此期间它不应该自动生成新的 id 值吗?因为它没有。
我做错了什么?
谢谢。
【问题讨论】:
-
我已经看到了,我想我的映射是正确的。我获取并设置所有类的属性等,如果我什至将注释放在声明类属性的前面,就像在示例中一样,它根本不会改变任何东西,在其他方面我已经得到了所有的东西,就像在示例中一样.
标签: java hibernate criteria hibernate-criteria