创建一个新的Hibernate表 [英] Creating a new Hibernate table
问题描述
@Entity
类,并且我需要将这些对象存储在一个新表中。这个类声明如下:pre code $ @Entity
@Table(name =DATA_REQUEST)
公共类DataRequest {
//一些字段,没什么特别的意思
}
所以:我是否需要手动创建表格(轻松完成)?或者我需要去其他地方告诉Hibernate我需要这张表吗?我已经看到 hibernate.cfg.xml
文件,它看起来是一个很好的开始。
您需要为hibernate.hbm2ddl.auto属性指定create。请阅读此处。这不建议在生产中使用,但仅用于测试目的。
So I'm still pretty new to Hibernate, and I'm working on a large-ish application that already has a database with several Hibernate tables. I'm working on a new feature, which includes a new @Entity
class, and I need these objects to be stored in a new table. The class is declared like this:
@Entity
@Table(name="DATA_REQUEST")
public class DataRequest {
//Some fields, nothing fancy
}
The DATA_REQUEST
table does not exist, nor do I have any data to store in it yet. I started the application up, expecting that it would either create the table or crash because it doesn't exist yet. Neither of these actually happened.
So: do I need to create the table manually (easily done)? Or do I need to go somewhere else to tell Hibernate that I need this table? I've seen the hibernate.cfg.xml
file, which looks like a good place to start.
You need to specify "create" for the "hibernate.hbm2ddl.auto" property. Read more details here. This is not recommended in production but only for testing purposes.
这篇关于创建一个新的Hibernate表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!