创建一个新的Hibernate表

编程入门 行业动态 更新时间:2024-10-15 16:25:12
本文介绍了创建一个新的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表

本文发布于:2023-10-23 05:19:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1519900.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:创建一个   Hibernate

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!