-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Changes on entities not committed
PostPosted: Tue May 17, 2011 4:58 am 
Beginner
Beginner

Joined: Thu Jan 06, 2011 6:19 am
Posts: 25
Hi again,

I have a strange behaviour in my unit tests. Before each test I create some entities and save them to the session so the index will be updated / created. After each test I clear the database, purge all entities from index and try to delete the index directory. This works for each single test but when I try to execute all tests I get the error that some index files cannot be deleted after a test and before the next test the created entities will not be committed to the index (which I found out by debugging, the data is not in the index) so the test executes with an error. I don't know, why this could happen. I changed to manual indexing strategy and index each entity in the PostUpdate and PostPersist Events. These events will be triggered correctly but the data does not appear in the index.

Here my code for the setUp and tearDown of the tests:
Code:

@Before
public void setUp() {
    // init GenericApplicationContext
    ...
    // createSomeTestData
    ProjectEntity pe = new ProjectEntityImpl();
    manager.createProject(pe);
}
public void tearDown() {
    // delete data
    // close GenericApplicationContext
    // delete index files and directories
    deleteFiles(indexDir)
}


Code for saving an entity:
Code:
@Transactional(readOnly=false, propagation=Propagation.REQUIRED)
public void createProject(ProjectEntity pe) {
    Session session = getSession();
    session.save(pe);
}


The code for my entity:
Code:
public class ProjectEntityImpl ... {
   @Field(name = "projectName", index = Index.UN_TOKENIZED)
    private String name;
    // more properties ...

    @PostUpdate
    @PostPersist
    public void updateIndex() {
       SearchManagerHolder.getSearchManager().updateIndex(this);
    }
    @PostRemove
    public void deleteIndex() {
       SearchManagerHolder.getSearchManager().deleteIndex(this);
    }
    ...
}


The search manager:
Code:
public void updateIndex(Object entity) {
    if (entity instanceof ProjectEntity) {
        FullTextSession fullTextSession = Search.getFullTextSession(getSession());
        fullTextSession.index(entity);
    }
}
public void deleteIndex(Object entity) {
    if ( instanceof ProjectEntity) {
         FullTextSession fullTextSession = Search.getFullTextSession(getSession());
         fullTextSession.purge(ProjectEntityImpl.class, ((ProjectEntity)entity).getID());
     }
}


So after each test I got the error that some index files cannot be deleted. I don't know why. The next tests failed because some data which is created in the setUp method does not appear in the index... Maybe you can give me a hint?

Regards, jacquipre


Top
 Profile  
 
 Post subject: Re: Changes on entities not committed
PostPosted: Tue May 17, 2011 6:40 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi,
maybe you don't close the Hibernate SessionFactory?
If you don't close it, the SearchFactory won't be closed, and it's possible that some of the index reader pools are still having the index opened.

http://community.jboss.org/wiki/HibernateSearchFAQ#How_do_I_properly_shutdown_Search

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Changes on entities not committed
PostPosted: Tue May 17, 2011 9:18 am 
Beginner
Beginner

Joined: Thu Jan 06, 2011 6:19 am
Posts: 25
I close the context and session factory BUT the problem was that we use the JPA entity manager to save and update our entities but for indexing and search we use the FullTextSession. I changed this with the FullTextEntityManager and now everything works as expected.

But thanks for your answer.

-- jacquipre


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.