Hibernate在插入期间忽略了一列

时间:2013-07-09 00:30:25

标签: java hibernate jpa entity field

我有一个这样的实体:

@Entity
@Table(name = "PERSON_TB")
public class Person implements Serializable {

   private static final long serialVersionUID = 32423423432434;

   @Id
   @Column(name = "ID")
   private Long personId;

   @Id
   @Column(name = "VALUE")
   private String value;

   @Column(name = "NAME")
   private String name;

   @Transient
   Address address;
   //getters / setters
}

这是我创建实体的代码:

 public Person createPerson( long id, String name, String value ) {
   Person p = new Person();
   p.setId(id);
   p.setName(name);
   p.setValue(value);
   return p;
 }

采用不同的方法:

  personCrudSvc.create(createPerson(192L, "Joe", "xyz");

这是错误:

  java.sql.SQLException: Attempt to insert null into a non-nullable column: column: VALUE  
 table: PERSON_TB in statement [insert into PERSON_TB (NAME, ID) values (?, ?)]

不确定这是否与此错误有关:

Hibernate Bug

我还有两个像这样创建的表,这些都很好。

1 个答案:

答案 0 :(得分:0)

试试这个

@Entity
@Table(name = "PERSON_TB")
public class Person implements Serializable {

   private static final long serialVersionUID = 32423423432434;

   @Id
   @Column(name = "personId")
   private Long personId;

   @Id
   @Column(name = "VALUE")
   private String value;

   @Column(name = "NAME")
   private String name;

   @Transient
   Address address;
   //getters / setters
}