Adding additional fields to hibernate beans that are not fields in the db table

Is it possible to add additional member variables to hibernate beans that are not fields in the actual database?

eg. I need to add hasComments to a member variable in MyEntity, and comments are not the actual field in db.

+4
source share
3 answers

Let either the field be transient or annotate it using the @Transient annotation.

+4
source

Watch it

@NotNull @Column(name = "comment") private String comment; @Column(name = "time") @Temporal(TemporalType.TIMESTAMP) @DateTimeFormat(style = "M-") private Date time; 

@Transient private line information;

+1
source

To quickly crack this error during development, you can use hbm2ddl to automatically create a database from sleep mappings and create fields in the table for transient properties. This does not solve the long-term problem, but allows you to continue working on other things until you have time to solve the main problem.

0
source

Source: https://habr.com/ru/post/1439812/


All Articles