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

Apache-Ignite integration as Hibernate 2nd level cache , does it understand annotations?

继续

我正在使用注释

@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-cache 不支持注解吗? 为什么我们需要在 ignite-configuration 中实现这个?

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

但是,我看不出有任何理由不改进它并创建一个 Ignite 票证:https://issues.apache.org/jira/browse/IGNITE-3603