Comments (6)
ManyToMany 应该不需要配@OnDissociate
吧 因为我配置了编译报错
from jimmer.
对比官方示例中的 测试如下:
未开启逻辑删除:
- 虚拟外键:主表删除OK 中间表删除OK
- 真外键:主表删除OK 中间表删除OK
开启逻辑删除:
- 虚拟外键:主表删除OK 中间表未删除
- 真外键:主表删除OK 中间表未删除
from jimmer.
我以为是删除一侧,伪外键中间表记录不能清理(之前一个版本已经修改了这个问题)
现在,是逻辑删除的问题,那就不光是中间表记录是否保留的问题了,子表外建也存在是否set null甚至连子表记录也一并删除的问题。
如果逻辑删除一条记录,既要删除中间表,又要清理子表外建甚至连子表记录也删除。那么,除了当前记录是hide还是delete外,更多的对周边的扩散操作和物理删除无差异,确定?
from jimmer.
这个issue提出的情况是:
因为当时中表无法添加逻辑删除字段 去处理逻辑删除的问题
所以第一反应是中间表的数据要删掉 (现在是未删除)
但后面与其他用户讨论之后,发现:
这是 一对数据 如果主表的数据处理的逻辑删除, 中间表无论是物理删除或者未删除 都是能导致数据不一致的情况。虽然逻辑删除的数据在系统层面来说已经不存在。但是免不了需要查询。也许是为了撕逼。也许是为了把数据恢复
目前感觉中间表可以加逻辑字段的话是最简单有效的方式
在这里说也希望能够有更多的用户来参与讨论或者说注意这个问题
from jimmer.
Resolved, @jointable now support both logical deletion and physical deletion based on logical deleted of either side.
from jimmer.
根据新版注释来看:
/**
* In general, if entities on either side support logical deletion,
* middle tables should also support logical deletion.
* Otherwise, error will be raised.
*
* <p>
* When entity on either side is logically deleted,
* the rows of middle tables should be logically deleted too.
* </p>
*
* <p>
* However, if you don't want intermediate table records to support soft deletion,
* turn this switch on. When an object at either side is logically deleted,
* the corresponding middle table records will be physically deleted.
* </p>
*/
boolean deletedWhenEndpointIsLogicallyDeleted() default false;
我试了一下 默认deletedWhenEndpointIsLogicallyDeleted
不配置 也就是 照旧配置:
@ManyToMany
@JoinTable(
name = "plan_menu_mapping",
joinColumns = [JoinColumn(name = "plan_id", foreignKeyType = ForeignKeyType.FAKE)],
inverseColumns = [JoinColumn(name = "menu_id", foreignKeyType = ForeignKeyType.FAKE)],
)
val menus: List<Menu>
测试的结果行为和以前一致
当添加 deletedWhenEndpointIsLogicallyDeleted=true
时 会先 物理删除 中间表数据 在逻辑删除 主表数据:
@ManyToMany
@JoinTable(
name = "tenant_plan_menu_mapping",
joinColumns = [JoinColumn(name = "tenant_plan_id", foreignKeyType = ForeignKeyType.REAL)],
inverseColumns = [JoinColumn(name = "menu_id", foreignKeyType = ForeignKeyType.REAL)],
deletedWhenEndpointIsLogicallyDeleted = true
)
val menus: List<Menu>
2024-02-22 18:12:30.651 INFO 14029 --- [ XNIO-1 task-1] o.b.jimmer.sql.runtime.ExecutorForLog : Execute SQL===>
Purpose: DELETE
SQL: delete from tenant_plan_menu_mapping
where
tenant_plan_id = 7149655580733345793
Affected row count: 2
JDBC response status: success
Time cost: 35ms
<===Execute SQL
2024-02-22 18:12:30.678 INFO 14029 --- [ XNIO-1 task-1] o.b.jimmer.sql.runtime.ExecutorForLog : Execute SQL===>
Purpose: DELETE
SQL: update tenant_plan set deleted = 1
where
id = 7149655580733345793
Affected row count: 1
JDBC response status: success
Time cost: 25ms
<===Execute SQL
我这里有一个疑问:当 deletedWhenEndpointIsLogicallyDeleted为默认值false时,中间表的逻辑删除的意思是不处理中间表数据吗?中间表要不要添加逻辑删除字段? 我看注释的意思的理解是:
-
主表有逻辑删除字段 配置好后 支持delete 转 update 逻辑删除 中间表没有逻辑删除自动不管 不执行(与之前一致)
-
主表有逻辑删除字段 当中间表也添加了逻辑删除字段 与主表行为一致 支持delete 转 update 逻辑删除
这个点我测试了下 往中间表也添加逻辑删除字段 但是结果与1一致 中间表在建模关系中是“不存在”的 是否加不加逻辑删除字段 都找不到这个字段???所以不处理 还是我理解的有误? -
主表有逻辑删除字段 主表执行deleted转update 但配置
deletedWhenEndpointIsLogicallyDeleted=true
不管中间表有没有添加逻辑删除字段
from jimmer.
Related Issues (20)
- [Feature Request] Enhance exception messages for client-side generation HOT 1
- [bug] openApi网页不RequestBody 显示的接口 HOT 1
- 广义乐观锁报错 HOT 1
- 递归查询时未按照`fetcher`进行查询 HOT 1
- [fr]考虑一下生产环境下路径会被转的场景 HOT 1
- [fr]关于dto与Hibernate Validator的结合 HOT 1
- [Bug] DTO `as` nested, generated fields is different HOT 1
- 这套框架能否实现类似mybatis plus acticerecord模式的效果 HOT 2
- springboot3中dto校验注解报错 HOT 1
- input类型的dto定义是否支持定义属性默认值? HOT 1
- UUID to varchar conversion problem HOT 8
- 如何能在拦截器DraftInterceptor获取到当前操作的表对象的表信息? HOT 1
- DTO equals() does not properly compare arrays HOT 1
- Expression.numeric().sql().in() not work. HOT 1
- DraftInterceptor not being called on update HOT 1
- 单向关联保存时实体设置了IDView的值 insert失败报错 HOT 2
- java: 来自批注处理程序 'org.babyfish.jimmer.apt.JimmerProcessor' 的受支持 source 版本 'RELEASE_8' 低于 -source '21' HOT 2
- [Bug] TS no generate enumerations that are only referenced by fetcher
- [BUG] When using annotations on prop in a dto file, if the parameter type of the annotation is class and 'Xxx.class' is used, it will result in a dto generation error
- [bug] 升级kotlin与ksp2.0.0之后实体使用default注解编译报错,切换回1.9.23之后正常。
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jimmer.