You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

能否通过注解配置Skyve使指定Document attribute不被持久化?

Skyve框架标记非持久化Document属性实现方法

可以直接通过注解实现需求,操作方式如下:

  • 在需要跳过持久化的属性对应的getter方法上,添加JPA标准的@Transient注解即可。Skyve的持久化层兼容JPA注解规则,识别到该注解后,会自动忽略该属性:既不会为其生成对应的数据库表字段,也不会在数据保存、更新、查询的流程中对该属性做持久化相关处理。
  • 该方案完全适配无存储业务价值的瞬态属性场景,被标记的属性值生命周期完全由业务代码自行控制,框架不会介入值的加载、持久化逻辑。

代码示例:

import javax.persistence.Transient;
import org.skyve.domain.types.Decimal;

// 你的Document实体类
public class CustomBizBean extends SkyvePersistableBean {
    // 其他正常持久化的属性定义
    private String tempDisplayValue;

    // 给瞬态属性的getter加@Transient注解
    @Transient
    public String getTempDisplayValue() {
        return tempDisplayValue;
    }

    public void setTempDisplayValue(String tempDisplayValue) {
        this.tempDisplayValue = tempDisplayValue;
    }
}

注意:不要把@Transient注解加到字段上,要标注在对应属性的getter方法上,否则Skyve的属性扫描逻辑可能无法正确识别该标记。

内容的提问来源于stack exchange,提问作者Damien Cooke

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.26 14:54:19