Reputation: 3514
I have a entity class User
. I want to add some more properties but to keep them nullable.
What is the annotation used for this in JPA?
I am using JPA in Google App Engine.
Upvotes: 27
Views: 55345
Reputation: 111
In your Entity class use Integer, Double, rather than int and double.
@Entity
public class AnyTable {
...
public double myValue; // !! dont use in this way - this can never be null!
public Double myValue; // BETTER !
Upvotes: 8
Reputation: 16311
Properties are nullable by default in JPA, except primitive types. You can control nullability using the nullable
property of the @Column annotation, like so:
//not nullable
@Column(nullable = false)
private String prop1;
//nullable
@Column(nullable = true)
private String prop2;
//default = nullable
@Column
private String prop3;
Upvotes: 56