在JPA中绝对需要列注释吗? [英] Column Annotation absolutly necessary in JPA?

查看:85
本文介绍了在JPA中绝对需要列注释吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我还有一个关于JPA的问题.如果要将变量存储在数据库中,是否需要用@Column注释每个成员变量?或者可以通过某些成员变量(在本示例中为"timestamp"字段)将其忽略,并且该字段将在每种可能的情况下存储在数据库中:

I have an another question concerning JPA. Is it necessary to annotate each member variable with @Column, if i want to store it in my database? Or is it possible to leave it out by some member variables (in these example the field "timestamp") and this field will be stored in database in each possible scenario:

@Entity
@Table(name = "usercontent")
public class UserContentEntity implements Persistable<Long> {

   /** serialVersionUID */
   private static final long serialVersionUID = 1L;

   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   private Long id;

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

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

   @Column(name = "bytes")
   @Lob
   private byte[] contentbytes;

   @Column
   private String creator;

   private Date timestamp;


   // get- and set methods
}

并且绝对有必要使用注释@Column吗?

And when it is absolutley necessary to use the annotation @Column?

非常感谢 迈克

推荐答案

否.除非您要覆盖默认的列命名或默认的数据存储列类型等,否则它不是必需的".无论如何,仅将@Column放置都不会这样做

No. its not "necessary", unless you want to override default column naming, or default datastore column type etc. And just putting @Column does nothing as such anyway

这篇关于在JPA中绝对需要列注释吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆