本文介绍了使用 JPA(带注释的实体)和 liquibase 进行休眠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

推荐答案

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

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/wiki but you can use "database urls" such as

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

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

if you have a hibernate xml conf file or

hibernate:ejb3:myPersistenceUnit

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

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

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

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

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

这篇关于使用 JPA(带注释的实体)和 liquibase 进行休眠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 07:26
查看更多