创建一个新的Hibernate表 [英] Creating a new Hibernate table

查看:106
本文介绍了创建一个新的Hibernate表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我对Hibernate仍然很陌生,而且我正在开发一个大型的ish应用程序,该应用程序已经有一个带有多个Hibernate表的数据库。我正在研究一个新功能,其中包含一个新的 @Entity 类,并且我需要将这些对象存储在一个新表中。这个类声明如下:

pre code $ @Entity
@Table(name =DATA_REQUEST)
公共类DataRequest {

//一些字段,没什么特别的意思

}

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表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆