Updating entity inserts duplicate property.

29 views
Skip to first unread message

Figo

unread,
Feb 15, 2012, 6:27:06 AM2/15/12
to Empire
Hello,

I have a problem when i try to update an entity. I use Empire 0.7,
when I use the merge method
(ProviderEntityManager.getEntityManager().merge(entity);) to update
entity in onthology data base, the property whose value has changed is
duplicated.

I will put an example. I have an entity named EntityTest with two
properties (id and label):

public class EntityTest {
String id;
String label;
}

I persist this entity with these values (it is just an example):
id="a1"; , label="label test 1";

The values are correctly persisted, i recover the EntityTest entity
and y change label value to: label="label test changed";

When I merge EntityTest entity to update the changes I can see in the
onthology data base these properties with their values:
id="a1";
label="label test 1";
label="label test changed";

I have two problems with this: first this is an error, I have done an
update and I do not want a new property with it value, and secondly I
can not recover the entity because EntityTest "label" property is a
String, not a List (or similar) and it gives an error.

Does anyone know why does it happen? and, does anyone know how to
solve this problem?

Greetings and thanks in advance.

Mike Grove

unread,
Feb 15, 2012, 8:11:18 AM2/15/12
to empir...@googlegroups.com
Can you please provide a working example that illustrates this
behavior? The "test" class you specified in the email is not empire
compatible, so I have no way of guessing what you're doing that
results in this behavior. A basic test case to do what you describe
gets me the expected results (no duplicated property) using the head
revision of Empire.

Cheers,

Mike

Figo

unread,
Feb 15, 2012, 9:05:23 AM2/15/12
to Empire
Hello,

I have this problem when I try to update ScpnProject entity, this
entity has a property named hasProject of class Project. In my case I
change in Project the property hasComment o hasName and I have the
problem I described.

Here I include the code of these two classes (interfaces in fact).

// ScpnProject
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++
@Entity
@RdfsClass("http://scipion.cnb.csic.es/Ontologies/
3DEM.owl#ScpnProject")
public interface ScpnProject extends ScpnAdministration, SupportsRdfId
{

@RdfProperty("http://scipion.cnb.csic.es/Ontologies/
3DEM.owl#hasScpnUserPrivilege")
@OneToMany(cascade={CascadeType.PERSIST, CascadeType.MERGE})
public List<? extends ScpnUserPrivilege> getHasScpnUserPrivilege();
public void setHasScpnUserPrivilege(List<? extends ScpnUserPrivilege>
theValue);

@RdfProperty("http://scipion.cnb.csic.es/Ontologies/
3DEM.owl#hasScpnCreator")
public ScpnUser getHasScpnCreator();
public void setHasScpnCreator(ScpnUser theValue);

@RdfProperty("http://scipion.cnb.csic.es/Ontologies/
3DEM.owl#hasScpnDir")
@OneToMany(cascade={CascadeType.PERSIST, CascadeType.MERGE})
public List<? extends DirPath> getHasScpnDir();
public void setHasScpnDir(List<? extends DirPath> theValue);

@RdfProperty("http://scipion.cnb.csic.es/Ontologies/
3DEM.owl#hasScpnAdmin")
public List<? extends ScpnUser> getHasScpnAdmin();
public void setHasScpnAdmin(List<? extends ScpnUser> theValue);

@RdfProperty("http://scipion.cnb.csic.es/Ontologies/
3DEM.owl#hasProject")
@OneToOne(cascade={CascadeType.PERSIST, CascadeType.MERGE})
public Project getHasProject();
public void setHasProject(Project theValue);

@RdfProperty("http://scipion.cnb.csic.es/Ontologies/
3DEM.owl#hasScpnLastActivityDate")
public Date getHasScpnLastActivityDate();
public void setHasScpnLastActivityDate(Date theValue);

}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++

// Project
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++
@Entity
@RdfsClass("http://scipion.cnb.csic.es/Ontologies/3DEM.owl#Project")
public interface Project extends Activity, SupportsRdfId {

@RdfProperty("http://scipion.cnb.csic.es/Ontologies/
3DEM.owl#hasComment")
public String getHasComment();
public void setHasComment(String theValue);

@RdfProperty("http://scipion.cnb.csic.es/Ontologies/
3DEM.owl#hasProcessingType")
public List<? extends EnumImageProcessingType> getHasProcessingType();
public void setHasProcessingType(List<? extends
EnumImageProcessingType> theValue);

@RdfProperty("http://scipion.cnb.csic.es/Ontologies/
3DEM.owl#hasDocument")
public List<? extends Path> getHasDocument();
public void setHasDocument(List<? extends Path> theValue);

@RdfProperty("http://scipion.cnb.csic.es/Ontologies/3DEM.owl#hasName")
public String getHasName();
public void setHasName(String theValue);

@RdfProperty("http://scipion.cnb.csic.es/Ontologies/
3DEM.owl#isFundedByGrant")
public List<? extends Grant> getIsFundedByGrant();
public void setIsFundedByGrant(List<? extends Grant> theValue);

@RdfProperty("http://scipion.cnb.csic.es/Ontologies/
3DEM.owl#hasBackgroundPublication")
public List<? extends Publication> getHasBackgroundPublication();
public void setHasBackgroundPublication(List<? extends Publication>
theValue);

@RdfProperty("http://scipion.cnb.csic.es/Ontologies/
3DEM.owl#hasPerson")
public List<? extends Person> getHasPerson();
public void setHasPerson(List<? extends Person> theValue);

@RdfProperty("http://scipion.cnb.csic.es/Ontologies/
3DEM.owl#hasCreationDate")
public Date getHasCreationDate();
public void setHasCreationDate(Date theValue);

@RdfProperty("http://scipion.cnb.csic.es/Ontologies/
3DEM.owl#hasPublication")
public List<? extends Publication> getHasPublication();
public void setHasPublication(List<? extends Publication> theValue);

@RdfProperty("http://scipion.cnb.csic.es/Ontologies/
3DEM.owl#hasLeader")
public List<? extends Person> getHasLeader();
public void setHasLeader(List<? extends Person> theValue);

}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++

Thanks for your attention.

Mike Grove

unread,
Feb 15, 2012, 11:10:33 AM2/15/12
to empir...@googlegroups.com
I was able to reproduce this in the case of using a auto-generated
instance from an interface, saving that bean to the EntityManager,
modifying it, and then merging the *same* object back to the entity
manager. I made a change to help alleviate this issue, but the
correct usage would be to call EntityManager.refresh on the object
before reusing and merging; that will correctly update the internal
state of the object to avoid duplicates. What happened in your case
is that it looked to Empire like the object was being persisted for
the first time so it did not delete anything since it thought there
was nothing to delete and thus you end up with the duplicates.

There is a changeset on the head revision which resolves this issue.

Cheers,

Mike

Figo

unread,
Feb 16, 2012, 4:15:40 AM2/16/12
to Empire
Ok, thanks, I will try this solution.
Reply all
Reply to author
Forward
0 new messages