1

I got "java.sql.SQLException: Field 'name' doesn't have a default value" when i save.

my save method

 gender = genderServices.getById(Integer.parseInt(carMap.get("gender").toString()));
        category.setGender(gender);
        category.setCategoryName(carMap.get("categoryName").toString());
        this.categoryServices.save(category);

Gender.class

@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
@Column(name="id")
private Integer id;

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

Category class

@ManyToOne
@JoinColumn(name="genderID")
private Gender gender;

How to i fix it?

1 Answer 1

1

The error is self explainable, it does mean their is "not null constraint" for "name" in db and you are not setting any value against the column.

Sign up to request clarification or add additional context in comments.

2 Comments

Usually real SQL structure is not coherent with JPA (for example JPA definiotions goes to never versions, db not)
No i set a value of name with category.setGender(gender).So gender name is not null when save

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.