I am using hibernate-ogm and Apache Deltaspike Data to save and remove a simple entity in mongoDB.
Saving works. But removing an entity, empty all fields except _id.
@Entity
public class MyEntity implements Serializable {
@Id
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid2")
private String id;
@NotNull
private String name;
@Version
private Integer version;
@ElementCollection
private Map<String, String> myMap;
public MyEntity() {
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Map<String, String> getMyMap() {
return myMap;
}
public void setMyMap(Map<String, String> myMap) {
this.myMap = myMap;
}
public Integer getVersion() {
return version;
}
public void setVersion(Integer version) {
this.version = version;
}
}
Correctly saved in mongodB
> db.MyEntity.find().pretty()
{
"_id" : "b359df37-d108-46c7-8c30-ae14c4064e00",
"name" : "my entity name",
"version" : 0,
"myMap" : {
"key1" : "value1",
"key2" : "value2"
}
}
Entity can’t be ‘entirely’ removed using hibernate-ogm and Deltaspike Data myRepository.attachAndRemove(myEntity) method. All fields are removed except “_id”.
> db.MyEntity.find().pretty()
{ "_id" : "b359df37-d108-46c7-8c30-ae14c4064e00" }
However, if I don’t use @Version, the entity is removed completely.
Any explanation for this behaviour/issue and how to avoid it is welcome.
Thanks in advance