开发者

How to make a property nullable in JPA - GAE/J?

I have a entity class User. I want to add some more properties but to keep them nullable.

What is the annotation use开发者_如何学运维d for this in JPA?

I am using JPA in Google App Engine.


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;


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 !
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜