2

我有一个这样的实体:

@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 (?, ?)]

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

休眠错误

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

4

1 回答 1

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
}
于 2013-07-09T04:52:20.850 回答