Apache-Ignite集成为Hibernate二级缓存,是否理解注释?

时间:2016-07-28 18:13:30

标签: hibernate spring-mvc caching gridgain ignite

继续 apache-ignite-integration-as-hibernate-2nd-level-cache-not-starting

我正在使用注释

@Cache(usage = CacheConcurrencyStrategy.READ_ONLY, region = "userType"

在我的实体中:

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.Table;

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

@Entity
@Table(name = "USER_TYPE", indexes = {
      @Index(columnList = "TYPE_SHORT_NAME", name = "TYPE_SHORT_NAME_UNIQUE_idx", unique = true), })
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY, region = "userType")

public class UserType implements Serializable {

  private static final long serialVersionUID = -628308304752474026L;

  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  @Column(name = "USER_TYPE_ID")
  private int userTypeId;

  @Column(name = "TYPE_SHORT_NAME", length = 20, nullable = false)
  private String typeShortName;

  @Column(name = "TYPE_LONG_NAME", length = 255)
  private String typeLongName;

  public UserType() {
  }

  public UserType(int userTypeId, String typeShortName, String typeLongName) {
      this.userTypeId = userTypeId;
      this.typeShortName = typeShortName;
      this.typeLongName = typeLongName;
  }

  @Override
  public int hashCode() {
      final int prime = 31;
      int result = 1;
      result = prime * result + ((typeLongName == null) ? 0 : typeLongName.hashCode());
      result = prime * result + ((typeShortName == null) ? 0 : typeShortName.hashCode());
      result = prime * result + userTypeId;
      return result;
  }

  @Override
  public boolean equals(Object obj) {
      if (this == obj)
          return true;
      if (obj == null)
          return false;
      if (!(obj instanceof UserType))
          return false;
      UserType other = (UserType) obj;
      if (typeLongName == null) {
          if (other.typeLongName != null)
              return false;
      } else if (!typeLongName.equals(other.typeLongName))
          return false;
      if (typeShortName == null) {
          if (other.typeShortName != null)
              return false;
      } else if (!typeShortName.equals(other.typeShortName))
          return false;
      if (userTypeId != other.userTypeId)
          return false;
      return true;
  }

  @Override
  public String toString() {
      return "UserType [userTypeId=" + userTypeId + ", typeShortName=" + typeShortName + ", typeLongName="
              + typeLongName + "]";
  }

  public int getUserTypeId() {
      return userTypeId;
  }

  public void setUserTypeId(int userTypeId) {
      this.userTypeId = userTypeId;
  }

  public String getTypeShortName() {
      return typeShortName;
  }

  public void setTypeShortName(String typeShortName) {
      this.typeShortName = typeShortName;
  }

  public String getTypeLongName() {
      return typeLongName;
  }

  public void setTypeLongName(String typeLongName) {
      this.typeLongName = typeLongName;
  }

}

但仍然需要在ignite-configuration中添加它。

<bean parent="transactional-cache">
    <property name="name" value="userType"/>
</bean>

点火缓存中是否不支持注释? 为什么我们需要在ignite-configuration中实现它?

1 个答案:

答案 0 :(得分:0)

注释有效。它定义了应缓存类型的缓存区域,并发策略和其他设置,但这并不意味着自动区域创建。您必须显式配置缓存。

但是,我没有看到为什么不改进这个并创建Ignite票证的任何理由:https://issues.apache.org/jira/browse/IGNITE-3603