Reputation: 39
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
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
Reputation: 64
Did you set constructor with lomboak?
@AllArgsConstructor
@NoArgsConstructor?
Check other column constrain like nullable =false
Upvotes: 1