Quote:
Could you please all the relevant java files and the code where you are trying to update reference and then i can try to emulate in my machine.
Ok, sorry for my omission.
The code where i try to update the reference is the following test:
TagPersistenceTest.java
Code:
public class TagPersistenceTest extends TestCase {
...
public void testSaveTagAndTaggedDocument() {
this.tag = new Tag();
//save Tag
this.persistenceManager.saveOrUpdate(this.tag);
//create Document
this.document = new Document();
//set Document's tags
Set<Tag> documentTags = new HashSet<Tag>();
documentTags.add(this.tag);
this.document.setTags(documentTags);
//save document reference into Tag
Set<Document> taggedDocuments = new HashSet<Document>();
taggedDocuments.add(this.document);
this.tag.setTaggedDocuments(taggedDocuments);
//update tag
this.persistenceManager.saveOrUpdate(this.tag);
//save Document
this.persistenceManager.saveOrUpdate(this.document);
//some tests: this are OK
List<Document> list = persistenceManager.findAll(Document.class);
Document docFromDB=list.get(0);
Set<Tag> tagsOfDocFromDB = docFromDB.getTags();
Iterator iter = tagsOfDocFromDB.iterator();
Tag documentTag=(Tag) iter.next();
assertEquals("Tag returned should be equal to the Tag passed",this.tag,documentTag);
assertEquals("Tag returned should have the same id of the Tag passed",this.tag.getId(),documentTag.getId());
assertEquals("Tag returned should store only one document",1,documentTag.getTaggedDocuments().size());
//trying to remove Document and some tests: also this tests are OK
this.persistenceManager.remove(docFromDB);
assertEquals("No one Document should be present in database", 0, this.persistenceManager.findAll(Document.class).size());
assertEquals("After removing the document, the tag should still be present in database", 1, this.persistenceManager.findAll(Tag.class).size());
//PROBLEMATIC TEST: this is NOT OK
assertTrue("Tag should have no tagged documents",taggedDocumentsOfReturnedTag.isEmpty());
}
...
}
The problem is the last test: as you can see Tag shouldn't store any tagged document, but at the end of the test the Tag's set of "taggedDocuments" still contains reference to Document.
This is my problem.
Thank you very much for your help