2016-07-28 162 views
0

在延续 apache-ignite-integration-as-hibernate-2nd-level-cache-not-startingApache-Ignite集成为Hibernate二级缓存,是否理解注释?

我利用注释

@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; 
    } 

} 

但仍需要在点燃的配置添加此。

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

ignite-cache中不支持注释吗? 为什么我们需要在点火配置中实现这个?

回答

0

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

但是,我看不出有什么理由不改善这一点并创建Ignite票证:https://issues.apache.org/jira/browse/IGNITE-3603

相关问题