简体   繁体   中英

Hibernate is ignoring a column during inserts

I have an entity like this:

@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
}

This is my code to create an Entity:

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

In a different method:

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

This is the error:

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

Not sure if this is related to this bug:

Hibernate Bug

I have two other tables created like this, and those are fine.

Try this

@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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM