It seems like the ReadWriteEhcacheEntityRegionAccessStrategy does not implement the remove method, that is inherited from the AbstractEhcacheAccessStrategy:
Code:
abstract class AbstractEhcacheAccessStrategy<T extends EhcacheTransactionalDataRegion> {
...
/**
* A no-op since this is an asynchronous cache access strategy.
*
* @see org.hibernate.cache.access.EntityRegionAccessStrategy#remove(java.lang.Object)
* @see org.hibernate.cache.access.CollectionRegionAccessStrategy#remove(java.lang.Object)
*/
public void remove(Object key) throws CacheException {
}
...
}
What is weird is that the NonStrictReadWriteEhcacheEntityRegionAccessStrategy have it implemented, and if you use it, it will work, and remove the entity from the cache.
So, try this if the NONSTRICT_READ_WRITE Strategy is possible to you:
Code:
@Entity
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Entity1 {
@Id
@GeneratedValue
private Long id;
@Column(length = 100)
private String name;
@Version
private long versioncontrol;
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 long getVersioncontrol() {
return versioncontrol;
}
public void setVersioncontrol(long versioncontrol) {
this.versioncontrol = versioncontrol;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((id == null) ? 0 : id.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Entity1 other = (Entity1) obj;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
return true;
}
@Override
public String toString() {
return "Entity1: " + id + ":" + name + ":" + versioncontrol;
}
}