简体   繁体   English

如何使用休眠Pojo文件重新创建数据库

[英]How can I recreate my database with hibernate pojo files

I lost my projects' database from my pc. 我从我的电脑上丢失了项目的数据库。 But I have my JSP project which includes hibernate. 但是我有包含休眠的JSP项目。 Whenever I run the project it says ' org.hibernate.exception.SQLGrammarException: Cannot open connection ' because the database not exist in the server. 每当我运行该项目时,它都会显示“ org.hibernate.exception.SQLGrammarException:无法打开连接 ”,因为服务器中不存在该数据库。 Can I recreate my database with the help of the POJO files? 我可以在POJO文件的帮助下重新创建数据库吗? I am using netbeans and MySQL server 5.1 我正在使用netbeans和MySQL服务器5.1

Yes you can recreate your database using hibernate. 是的,您可以使用休眠方式重新创建数据库。 In our session factory you need to set the following property. 在我们的会话工厂中,您需要设置以下属性。

 <property name="jpaProperties">
   <props>
     <prop key="hibernate.hbm2ddl.auto">create</prop>
   </props>
 </property>

hibernate.hbm2ddl.auto Automatically validate or exports schema DDL to the database when the SessionFactory is created hibernate.hbm2ddl.auto创建SessionFactory时自动将架构DDL验证或导出到数据库

There are a couple of caveats you need to understand: 您需要了解以下几点警告:

  1. This will only recreate objects which you had mapped. 这只会重新创建您已映射的对象。 This process will not recreate any database object which you may have had but didn't have mapped. 此过程不会重新创建您可能已经拥有但尚未映射的任何数据库对象。
  2. Certain object names may not be named what they were previously. 某些对象名称可能没有以前的名称。 One classic example would be the names of your foreign-key constraints. 一个经典的例子是外键约束的名称。

This will at least get you back up with a majority of what you lost at the very least. 这至少会使您至少损失了大部分损失。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何创建Hibernate Pojo和hbm文件 - How to create Hibernate Pojo's and hbm files 我可以在Hibernate Filter中使用POJO吗? - Can I use POJO in Hibernate Filter? 如何使用递归来重新创建图形? - How can I recreate my graphic using recursion? 数据库中的 Hibernate 映射文件和 pojo 时发生错误 - Errors occur when Hibernate Mapping Files and pojo's from the database 如何轻松将POJO转换为JSON数据? - How can I easily convert my POJO's into JSON data? 太多的样板,我怎样才能减少我的POJO建造者? - Too much boilerplate, how can I reduce my POJO builders? Hibernate如何在运行时而不是在编译时删除并重新创建数据库? - How to have Hibernate drop and recreate database during runtime, not at compile time? 如何使用休眠逆向工程工具生成带有ejb3注释的pojo? - How can i use hibernate reverse engineering tools to generate pojo with ejb3 annotation? 如果传入请求的字段少于或多于 POJO,我如何告诉 Hibernate 验证器抛出异常 - How can I tell Hibernate Validator to throw exception if the incoming request has less or extra fields than the POJO 我可以将POJO标记为Hibernate实体,而Apache Spark使用此POJO吗? - Can I mark POJO as Hibernate entity, while this POJO is used by Apache Spark?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM