顯示具有 📚Spring Boot 標籤的文章。 顯示所有文章
顯示具有 📚Spring Boot 標籤的文章。 顯示所有文章

2024-09-11

做 Hibernate envers 設定時遇到的坑

這篇算是延續先前《SpringBoot 使用多個資料庫連線》的狀況

我今天想要使用Hibernate envers來處理資料的版控。

原先我是這樣處理的:

  1. pom.xml 加上library

    <dependency>
    	<groupId>org.hibernate</groupId>
    	<artifactId>hibernate-envers</artifactId>
    </dependency>
  2. application.properties 加上設定

    spring.jpa.properties.hibernate.envers.audit_table_suffix=_rev
    spring.jpa.properties.hibernate.envers.revision_field_name=rev
    spring.jpa.properties.hibernate.envers.revision_type_field_name=revtype
    
  3. Hibernate Entity 加上 @Audit
    import javax.persistence.Entity;
    import javax.persistence.Table;
    
    import org.hibernate.envers.Audited;
    
    @Entity
    @Audit
    @Table(name = "my_entity")
    class MyEntity{
    	// 中略
    }

然而,實際執行時,Hibernate 處理版控資料時,都想要存入 my_entity_AUD,即

insert into `my_entity_AUD` 
# 下略

2021-09-02

紀錄一下自己用 Spring Boot 是如何建立一個控制台應用程式(命令列工具/console application)

如題,最近因為工作需求,要建立一個控制台應用程式

基於環境已經有安裝 Java 了,所以沒用自己愛用的 go 來寫。

既然要用 Java ,為求方便,所以用 Spring Boot。沒想到用 Spring Boot 寫控制台應用程式的教學資源這麼少。所以在此紀錄,