Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Column Annotation absolutly necessary in JPA?

Tags:

java

jpa

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
}

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

Thanks a lot Maik


1 Answers

No. it's 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

like image 122
Neil Stockton Avatar answered Sep 08 '25 00:09

Neil Stockton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!