java 使用 JPA(带注释的实体)和 liquibase 进行休眠

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/776787/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 13:43:28  来源:igfitidea点击:

Hibernate using JPA (annotated Entities) and liquibase

javahibernatejpaliquibase

提问by Schildmeijer

liquibase is a perfect alternative to hibernate's hbm2ddl_autoproperty if you are using xml-mapping. But Im using JPA annotation (hibernate annotations). Is it possible to use liquibase then?

如果您使用 xml 映射,liquibase 是 hibernate 的hbm2ddl_auto属性的完美替代品。但我使用 JPA 注释(休眠注释)。那么可以使用 liquibase 吗?

采纳答案by Nathan Voxland

Yes, Liquibase uses hibernate's metadata classes, which are the same whether you use xml mappings or annotations. You do need a hibernate config file to point liquibase to, but your mappings can be xml or jpa annotations. More information can be found at https://github.com/liquibase/liquibase-hibernate/wikibut you can use "database urls" such as

是的,Liquibase 使用 hibernate 的元数据类,无论您使用 xml 映射还是注释,这些类都是相同的。您确实需要一个休眠配置文件来指向 liquibase,但您的映射可以是 xml 或 jpa 注释。可以在https://github.com/liquibase/liquibase-hibernate/wiki找到更多信息,但您可以使用“数据库网址”,例如

hibernate:classic:com/example/hibernate.cfg.xml

if you have a hibernate xml conf file or

如果你有一个 hibernate xml conf 文件或者

hibernate:ejb3:myPersistenceUnit

if you have a META-INF/persistence.xml, or

如果你有一个 META-INF/persistence.xml,或者

hibernate:spring:com.example?dialect=org.hibernate.dialect.MySQL5Dialect

if you would like auto-generate a JPA configuration based on a java package containing annotated Entities.

如果您想根据包含带注释实体的 java 包自动生成 JPA 配置。