DATA_REQUEST 表不存在,我也没有任何数据可以存储。我启动了应用程序,希望它可以创建表或崩溃,因为它还不存在。这些都没有发生。
所以:我是否需要手动创建表格(轻松完成)?或者我需要去其他地方告诉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表
发布评论