Komal Goyal
Komal Goyal

Reputation: 263

Adding extra fields in hibernate beans that are not fields in db table

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

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

Upvotes: 4

Views: 4276

Answers (3)

CodeMed
CodeMed

Reputation: 9201

For a quick hack to move past this error during development, you can use hbm2ddl to create the database automatically from the hibernate mappings, and it will create fields in the table for the transient properties. This does not solve the long term problem, but it lets you continue to work on other things until you have time to resolve the underlying issue.

Upvotes: 0

Vinit Prajapati
Vinit Prajapati

Reputation: 1613

See this

@NotNull
@Column(name = "comment")
private String comment;

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

@Transient private String information;

Upvotes: 1

Aleksander Blomskøld
Aleksander Blomskøld

Reputation: 18552

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

Upvotes: 4

Related Questions