我只是发现我的休眠验证不起作用。我正在使用带有注释的hibernate3。请检查以下代码。
@Entity
@Table(name = "registration")
public class Pojo implements Serializable{
@Id
@Column(name = "id")
@NotNull
private int id;
@Column(name = "name", length=5)
@NotNull
private String name;
@Column(name = "surname", length=5)
@NotNull
private String surname;
@Column(name = "address", length=5)
@NotNull
private String address;
getters and setters
}
以下是我的 servlet
System.out.println("Kshitij-----");
PrintWriter out = response.getWriter();
SessionFactory sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
Session session = sessionFactory.openSession();
Transaction transaction = session.beginTransaction();
Pojo r = new Pojo();
r.setId(Integer.valueOf(request.getParameter("id")));
r.setName(request.getParameter("name"));
r.setSurname(request.getParameter("surname"));
r.setAddress(request.getParameter("address"));
session.save(r);
transaction.commit();
session.close();
out.println("Success.....");
它正在插入没有值的记录。我应该添加一些新的东西吗?