2014-10-20 54 views
0

当我覆盖实体equalshashcode方法时,我的Arquillian无法部署将实体类添加到WebArchice时。Arquillian无法部署覆盖等于和散列码

环境
  • TomEE 1.7.1
  • 的Arquillian-tomee包埋1.7.1
  • 的Arquillian-的junit容器1.1.5.Final
  • org.hibernate作为4.1.4.Final

下面是实体类:

@Entity 
public class Property implements Serializable { 

    @Id 
    @GeneratedValue(strategy = GenerationType.IDENTITY) 
    @Column(name = "ID") 
    private Long id; 
    @Column(name = "PROP_NAME", nullable = false, unique = true) 
    private String name; 
    private String description; 
    private boolean isModifiable; 
    @Column(name = "PROP_VALUE", nullable = false) 
    private String value; 

    public Property() { 
    } 

    public Property(Long id, String name, boolean isModifiable, String value) { 
     this.id = id; 
     this.name = name; 
     this.isModifiable = isModifiable; 
     this.value = value; 
    } 

    public Long getId() { 
     return id; 
    } 

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

    public String getName() { 
     return name; 
    } 

    public void setName(String name) { 
     this.name = name; 
    } 

    public String getDescription() { 
     return description; 
    } 

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

    public boolean isIsModifiable() { 
     return isModifiable; 
    } 

    public void setIsModifiable(boolean isModifiable) { 
     this.isModifiable = isModifiable; 
    } 

    public String getValue() { 
     return value; 
    } 

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

    @Override 
    public boolean equals(Object obj) { 
     if (obj == null) { 
      return false; 
     } 

     if (getClass() != obj.getClass()) { 
      return false; 
     } 

     final Property other = (Property) obj; 
     if (!this.id.equals(other.id)) { 
      return false; 
     } 

     if (!this.name.equals(other.name)) { 
      return false; 
     } 

     if (!this.value.equals(other.value)) { 
      return false; 
     } 

     if ((this.description == null ? other.description != null : !this.description.equals(other.description))) { 
      return false; 
     } 

     return this.isModifiable == other.isModifiable; 
    } 

    @Override 
    public int hashCode() { 
     int hash = 3; 
     hash = 97 * hash + (id == null ? 0 : (int) (this.id^(this.id >>> 32))); 
     hash = 97 * hash + Objects.hashCode(this.name); 
     hash = 97 * hash + Objects.hashCode(this.description); 
     hash = 97 * hash + (this.isModifiable ? 1 : 0); 
     hash = 97 * hash + Objects.hashCode(this.value); 
     return hash; 
    } 
} 

这就是我将类添加到WebArchice类的方法。

WebArchive webArchive = ShrinkWrap.create(WebArchive.class); 
webArchive.addClasses(Property.class); 

当我删除从我Propertyequalshashcode方法,它的Arquillian部署。

如何让Arquillian与覆盖equalshashcode方法的类一起工作?

回答

0

解决方案如下,让我开始工作。

当覆盖equalshashcode方法不直接访问类变量。 使用getter方法从equalshashcode中访问它们。

在我改变了从equalshashcode中访问变量的方式后,Arquillian成功地在类中部署了。