如何使用JHipster和Hibernate Envers [英] How to use JHipster and Hibernate Envers

查看:52
本文介绍了如何使用JHipster和Hibernate Envers的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在弄清楚如何使用Hibernate Envers和JHipster时遇到麻烦.

I am having trouble figuring out how to use Hibernate Envers and JHipster.

我正在使用PostgreSQL来存储数据,以及最新的Jhipster 2.6.0 我只是生成了一个JHipster应用程序,根本没有进行任何修改. User域类扩展了AbstractAuditingEntity类,该类具有@Audited批注,但是在编辑用户时,数据库中没有创建t_user_aud表.

I am using PostgreSQL to store the data, and latest Jhipster 2.6.0 I just generated a JHipster application, with no modifications at all. The User domain class extends the AbstractAuditingEntity class, which has the @Audited annotation, but when editing a user there's no t_user_aud table created in the database.

是否需要进行任何配置才能使Hibernate Envers保存修改?

Is there any configuration needed in order to have Hibernate Envers saving modifications ?

推荐答案

我有一个github存储库,该存储库显示了如何为jhipster 2.6.0的postgres添加它.

I've got a github repository that shows how to add it for postgres for jhipster 2.6.0

一旦生成了jhipster应用程序,就创建了postgres数据库,生成了实体(例如yo jhipster:entity Foo),并且应用了所有以前的数据库修订版(运行mvn spring-boot:run以确保它运行以前的数据库修订版).

Once you have your jhipster app generated, your postgres db created, entity generated (e.g. yo jhipster:entity Foo), and all previous db revision applied (run mvn spring-boot:run to make sure it runs previous db revisions).

警告:"spring-data-envers"会导致QueryDsl中断. (请参阅: https://github.com/spring-projects/spring- data-envers/issues/30 ).此外, https://github.com/spring-projects /spring-data-envers/issues/33#issuecomment-108796022 说,"spring-data-envers"项目不是优先事项. Jhipster已经包含的"hibernate-envers"项目使您可以使用envers而不需要"spring-data-envers" ...因此,如果要避免QueryDsl问题,请跳过步骤1和3删除"spring-data-envers".

Warning: 'spring-data-envers' causes breaks QueryDsl. (See: https://github.com/spring-projects/spring-data-envers/issues/30). Furthermore, https://github.com/spring-projects/spring-data-envers/issues/33#issuecomment-108796022 says that the 'spring-data-envers' project is not a priority. Jhipster's already-included 'hibernate-envers' project lets you use envers without needing 'spring-data-envers'...so if you want to avoid QueryDsl problems, remove 'spring-data-envers' by skipping step 1 and 3.

  1. 将spring-data-envers添加到pom.xml.

  1. Add spring-data-envers to your pom.xml.

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-envers</artifactId>
    <version>0.2.0.RELEASE</version>
</dependency>

  • 在域包中的实体类中添加@Audited

    注意:liquibase-3.3.2无法将INT4识别为postgres的autoIncrement,因此会抛出该错误 java.lang.RuntimeException: Unknown property autoIncrement for liquibase.datatype.core.UnknownType INT4.您可以改为将其更改为"SERIAL",但是您将与进一步生成的变更日志进行斗争.我建议升级到liquibase-3.3.3(请参见 https://github.com/liquibase/liquibase/commit/1602ddf1cf4968753e09a6858fc1580230a2fb44 ),但您还必须在pom.xml中的liquibase插件配置中添加<liquibaseShouldRun>true</liquibaseShouldRun>.

    Note: liquibase-3.3.2 doesn't recognize INT4 for autoIncrement for postgres and would throw this java.lang.RuntimeException: Unknown property autoIncrement for liquibase.datatype.core.UnknownType INT4. You can change it to 'SERIAL' instead but you'll fight with further generated changelogs. I'd recommend upgrading to liquibase-3.3.3 (see https://github.com/liquibase/liquibase/commit/1602ddf1cf4968753e09a6858fc1580230a2fb44) but you'll also have to add <liquibaseShouldRun>true</liquibaseShouldRun> to the liquibase plugin configuration in your pom.xml.

    注意::当您运行测试(使用H2)时,H2期望REVTYPE使用tinyint而不是smallint.要么忽略测试,要么添加类似的内容

    Note: When you run your tests (using H2), H2 expects tinyint instead of smallint for the REVTYPE. Either ignore the tests or add something like this

    <changeSet author="sdoxsee" id="1426529918864-0">
       <sql dbms="postgresql">CREATE DOMAIN "tinyint" AS smallint</sql>
    </changeSet>
    

    这样H2会快乐,而postgres会快乐.否则,您会得到

    so that H2 will be happy and postgres will be happy. Otherwise you'll get

    org.hibernate.HibernateException: Wrong column type in JHIPSTER.PUBLIC.T_FOO_AUD for column REVTYPE. Found: smallint, expected: tinyint

    运行mvn test

    1. mvn spring-boot:run再次将应用更改日志
    2. 通过正在运行的应用创建实体
    3. 打开pgAdmin3来查看审核表的历史记录!
    1. mvn spring-boot:run again will apply the changelog
    2. Create an entity through the running app
    3. Open pgAdmin3 to see the audit table history!

    希望这会有所帮助.

    我已经包含了源代码: https://github.com/sdoxsee/jhipster-app -envers

    I've included the source: https://github.com/sdoxsee/jhipster-app-envers

    有用的参考资料:

    这篇关于如何使用JHipster和Hibernate Envers的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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