Deep Shah
Deep Shah

Reputation: 39

org.hibernate.PropertyValueException: not-null property references a null or transient value while using Spring Boot

I am getting this error while inserting data into table using Spring boot framework via POSTMAN RESTAPI:

org.hibernate.PropertyValueException: not-null property references a null or transient value: com.example.demo.model.Employee.firstName

This is my Employee Entity class:

@Data
@Entity
@Table(name="employees")

public class Employee {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;

    @Column(name = "first_name", nullable = false)
    private String firstName;

    @Column(name = "last_name")
    private String lastName;

    @Column(name = "email")
    private String email;
}

Upvotes: 1

Views: 2353

Answers (3)

nyaugenya
nyaugenya

Reputation: 29

remove the @Column and it will work

Upvotes: -1

Courage Oghogho
Courage Oghogho

Reputation: 1

Find a way to initialize the String firstName attribute. You actually enforced a not null contrail but may not have sent the value before attempting to persist.

So, when u create the object for the Employee class, make sure u set a value for the first name before u save it to the database.

Upvotes: 0

katyRosale
katyRosale

Reputation: 64

Did you set constructor with lomboak?

@AllArgsConstructor
@NoArgsConstructor? 

Check other column constrain like nullable =false

Upvotes: 1

Related Questions