Hibernate 缓存 关于注解方式

要引入

import org.hibernate.annotations.Cache;

在类前面添加:

@Cache(usage= CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)

可选项有:

  • read-only

  • read-write

  • nonstrict-read-write

  • transactional

完整示例:

package com.hlcg.main.bean;


import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import javax.persistence.*;

/**
 * Created with IntelliJ IDEA.
 * User: HYY
 * Date: 13-10-20
 * Time: 下午1:04
 * To change this template use File | Settings | File Templates.
 */
@Entity
@Table(name = "hl_key_value")
@Cache(usage= CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class KeyValue {
    private Integer id;//主键
    private String key;
    private String value;
    private Integer type;//类型
    private String description;//描述、简介


    @Id
    @SequenceGenerator(name = "increment")
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "increment")
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @Column(name = "`key`", unique = true,nullable=false, length = 200)
    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }


    @Column(name = "`value`", length = 3000)
    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    @Column(name = "`type`")
    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    @Column(length = 300)
    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }
}

注意key,value都是数据库的关键字 要加上``才行。

 

转载于:https://www.cnblogs.com/wuyou/p/3444028.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值