简体   繁体   中英

Can we add a column in DB without adding it to the hibernate object?

在数据库中添加额外的列会中断休眠状态吗?

It will be OK as long as the column is not defined as NOT NULL , or has a DEFAULT value defined.

Insert statements that Hibernate issues will not provide a value for the column (obviously), but the statements it produces will be syntactically correct, even if it doesn't know about the column - the column and its value simply won't be mentioned in the insert statement.

You may consider using a database trigger to maintain values in that column if they must be derived in some special way, although would caution using database kung fu unless it's absolutely necessary, for example if you don't have control over the source code for the hibernate entity classes and the column must be some particular value that couldn't be declared as a column default.

Update and select statements would require no special treatment.

如果要通过休眠自动更新表,则可以在休眠配置文件中使用以下内容

 <property name="hbm2ddl.auto">create</property>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM