JPA实体ID - 长或长 [英] JPA entity id - long or Long
问题描述
您的实体的ID应该是 long (原始类型)还是 要选择什么? long或long? 我认为让Long更好,因为通过检查 小原始物的优点:占用空间少一些。 PS:两者都是正确的&支持根据JPA规范和这个问题的答案是某种基于意见的。 Should the ID of your Entity be long (primitive type) or Long (object type)? What to choose? long or Long?
I consider having Long is better, as is more correct to check whether an entity has persistent identity by checking against the The small advantage of the primitive: it takes a bit less space. PS:Both are correct & supported according to the JPA specification and the answers to this question are somehow opinion-based. 这篇关于JPA实体ID - 长或长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
@Entity
@Table(name =COUNTRY)
public class CountryEntity实现java.io.Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name =ID)
私人长ID;
@Column(name =NAME)
私人字符串名称;
@Column(name =CURRENCY)
私人字符串货币;
@Column(name =PEOPLE)
私人长者;
@Column(name =SIZE)
私人长尺寸;
Public CountryEntity(){
}
null
值来检查实体是否具有持久性标识更为正确(在MySQL中,您可以有一个值为0的ID)。像Spring这样的一些库基于逻辑中的Long类型(默认情况下)。请参阅实现。
@Entity
@Table(name = "COUNTRY")
public class CountryEntity implements java.io.Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "ID")
private long id;
@Column(name = "NAME")
private String name;
@Column(name = "CURRENCY")
private String currency;
@Column(name = "PEOPLE")
private Long people;
@Column(name = "SIZE")
private Long size;
public CountryEntity() {
}
null
value (in MySQL you can have an ID of value 0). Also some libraries like Spring base on an ID of type Long (by default) in their logic. See this implementation for an example.