源码

java-休眠第二级缓存一对一无效


我将Ehcache提供程序用于Hibernate 2级缓存.它缓存一对多的集合,并用@Cache注释,但不缓存一对一:

//hb annotations
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE, region = "user")
public class User {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;

    @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, mappedBy = "user")
    @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE, region = "details")
    private Details details;

    //getters, setters, constructors etc.

}

//hb annotations
public class Details {

    @GenericGenerator(name = "generator", strategy = "foreign",
    parameters = @Parameter(name = "property", value = "user"))
    @Id
    @GeneratedValue(generator = "generator")
    @Column(unique = true, nullable = false)
    private Integer id;

    @OneToOne
    @PrimaryKeyJoinColumn
    private User user;

    //getters, setters, constructors ets.

}

我使用Spring JpaRepository来获取数据:

userRepository.findOne(id);
(0)

本文由 投稿者 创作,文章地址:https://blog.isoyu.com/archives/java-xiumiandierjihuancunyiduiyiwuxiao.html
采用知识共享署名4.0 国际许可协议进行许可。除注明转载/出处外,均为本站原创或翻译,转载前请务必署名。最后编辑时间为:11月 12, 2019 at 03:26 上午

热评文章