2020年8月24日 星期一

JavaModelGeneratorConfiguration

可以用在Database Reverse Engineer

http://mybatis.org/generator/apidocs/org/mybatis/generator/config/JavaModelGeneratorConfiguration.html

package org.mybatis.generator.config;
public class JavaModelGeneratorConfiguration extends PropertyHolder {


ref:
https://github.com/lihengming/spring-boot-api-project-seed/blob/master/src/test/java/CodeGenerator.java

Four Ways of MyBatis_Generator (MBG) Reverse Engineering  
https://programmer.ink/think/four-ways-of-mybatis_generator-mbg-reverse-engineering.html

fieldItem_index = 0

因為通常pk會放在第一個欄位
可以用這種比較笨的方式判斷

    <#if fieldItem_index = 0>
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    </#if>


ref:
https://freemarker.apache.org/docs/ref_directive_list.html#ref_list_accessing_state

Invalid object name 'hibernate_sequence'

https://stackoverflow.com/questions/49037803/sql-server-2016-invalid-object-name-hibernate-sequence

Avoid GenerationType.AUTO

Set it explicit to GenerationType.IDENTITY or GenerationType.SEQUENCE depending on what you want or your DB supports.

中文訊息:
com.microsoft.sqlserver.jdbc.SQLServerException: 無效的物件名稱 'hibernate_sequence'

2020年8月20日 星期四

SpringBootCodeGenerator

 https://github.com/moshowgame/SpringBootCodeGenerator

 

基于SpringBoot2+Freemarker的代码生成器,

√支持mysql/oracle/pgsql三大数据库, 

√用DDL-SQL语句生成JPA/JdbcTemplate/Mybatis/MybatisPlus/BeetlSQL相关代码

 

ref:

https://zhengkai.blog.csdn.net

  

2020年8月5日 星期三

@Transactional(rollbackFor = Exception.class)

因為Spring的設計之初參考EJB,預設只會對unchecked exceptions去rollback,如果自己開發的程式對自訂Business Exception(比如傳入的訂單金額為負數)需要RollBack,需要用annotation方式設定@Transactional(rollbackFor = Exception.class),對checked exceptions也rollback。


Although EJB container default behavior automatically rolls back the transaction on a system exception (usually a runtime exception), EJB CMT does not roll back the transaction automatically on anapplication exception (that is, a checked exception other than java.rmi.RemoteException). While the Spring default behavior for declarative transaction management follows EJB convention (roll back is automatic only on unchecked exceptions), it is often useful to customize this behavior.


ref: