2016-07-28 23 views
0

In Fortsetzung zu apache-ignite-integration-as-hibernate-2nd-level-cache-not-startingApache-Ignite Integration als Hibernate 2nd Level Cache, versteht es Annotationen?

Ich mache Gebrauch von Annotation

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

in meinem Entity:

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

} 

Aber noch braucht dies in Ignite-Konfiguration hinzuzufügen.

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

Werden Anmerkungen nicht in ignite-cache unterstützt? Warum müssen wir dies in der ignite-Konfiguration implementieren?

Antwort

0

Anmerkung funktioniert. Es definiert die Cache-Region, in der der Typ zwischengespeichert werden soll, die Nebenläufigkeitsstrategie und andere Einstellungen, dies bedeutet jedoch nicht die automatische Erstellung der Region. Sie müssen den Cache explizit konfigurieren.

Ich sehe jedoch keinen Grund, warum dies nicht zu verbessern und ein Ignite-Ticket erstellt: https://issues.apache.org/jira/browse/IGNITE-3603