如何使用JPA 2.1属性javax.persistence.schema-generation.database.action? [英] How to use JPA 2.1 property javax.persistence.schema-generation.database.action?

查看:345
本文介绍了如何使用JPA 2.1属性javax.persistence.schema-generation.database.action?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

javax.persistence.schema-generation.database.action的允许值为

  • 没有(没有任何用处...)
  • create(仅在第一次启动应用程序时才起作用,因为如果创建了已经存在的模式,则由于大多数数据库(例如derby 11.x)而导致所有其他启动都失败了
  • 拖放并创建(它永远不会保留任何数据,这引发了一个问题,即为什么它是持久性标准规范的一部分-假定用于调试目的)
  • drop(对称失败create成功
  • none (that doesn't serve anything...)
  • create (which only works the first time the application is started because all further starts fail due to most databases (e.g. derby 11.x) fail if a schema that already exist is created
  • drop-and-create (which wouldn't ever persist any data which raises the question why it's part of a persistence standard specification - assuming debugging purpose)
  • drop (symetrically fails create succeeds

绝对没有使用这些值的选项,我也看不出它们的规范-假设您不希望应用程序的用户一次(使用create)启动应用程序,请破解persistence.xml文件,将您的应用程序重新打包,并与none一起使用.那么,如何使用它们来在整个应用程序重启期间持久化Java对象呢?

which leaves absolutely no option to use any of these value nor do I see any sense in their specification - assuming you don't want the user of your application to start the application once (with create), hack the persistence.xml file, repackage you application and use it with none. How to use them to persist Java objects accross application restarts, then?

我知道Hibernate的hibernate.hbm2ddl.auto效果很好,但是我试图解决JPA 2.1实现可移植方法的奥秘.

I know about Hibernate's hibernate.hbm2ddl.auto which works great, but I'm trying to get the mystery solved for a JPA 2.1 implementation portable approach.

推荐答案

几乎没有什么奥秘(它们在规范或文档中定义了任何不错的JPA实现).这是在创建EMF时运行的(如果通过Persistence调用,则作为单独的前期操作).

Hardly any mystery (and they are defined in the spec, or in the docs for any decent JPA implementation). This is run when the EMF is created (or as a separate up front operation if invoked via Persistence.).

"none"意味着什么都不做...所以就像JPA一直做的事情一样,即持久性.它不是为了任何目的",只是为了不做任何额外的事情!

"none" means do nothing ... so do like JPA has always done things i.e just persistence. It isn't there to "serve any purpose", just to not do anything extra!

"create"表示为实体创建表(因此假定尚不存在).显然,大多数JPA提供程序都会在创建表之前检查表是否存在,因此它不会在以后的使用中失败".

"create" means create the tables for the entities (so it is assumed to not exist yet). Clearly most JPA providers will check existence of tables before creation, so it won't "fail on subsequent uses".

"drop"表示删除实体的表(因此,当作为独立进程运行时,例如在测试后进行清理).

"drop" means drop the tables for the entities (so when running as stand alone process, clean up after tests for example).

"drop-and-create"删除并为实体创建表,因此摆脱那里的内容并从头开始.与持久数据无关,但是这些选项都不是.

"drop-and-create" drop and create the tables for the entities, so get rid of what was there and start from scratch. Nothing to do with persisting data, but then none of these options are.

如前所述,其中某些选项对于测试最有用.在现实世界中,大多数人会生成DDL,对其进行优化以满足其DBA要求,然后手动生成它,然后仅运行JPA,因此在运行时不使用此属性

As said, some of these options are most useful for testing. In a real world situation most people would generate DDL, refine it to meet their DBAs requirements, and generate it manually, then just run JPA hence no use this property at runtime

这篇关于如何使用JPA 2.1属性javax.persistence.schema-generation.database.action?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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