[jboss-user] [EJB 3.0] - entitymanager flush is not flushing

kgreene do-not-reply at jboss.com
Sun Feb 17 13:11:21 EST 2008


Hi,

I'm new to jboss and ejb.  I am trying to have the EntityManager update the database immediately versus waiting until the code completes.  I tried using flush, but the database does not get updated until after the code completes.  Any ideas?


Watcher.java

@Stateless
@Clustered
public class Watcher 
implements WatcherIntLocal, WatcherIntRemote
{

       @Resource
       private SessionContext context;
       @PersistenceContext (unitName="WatcherDB")
       private EntityManager em;


public void checkForNewFiles() throws WatcherException 
{
         try 
        {
	List validFiles = findValidFiles();
	addToQueue(validFiles);
			
        } 
        catch (Throwable e) 
       {
	e.printStackTrace();
	throw new WatcherException(e);
       }
}

public List findValidFiles() throws WatcherException 
{
     //iterate thru a list of files and search for certain extensions
    //if the file name matches those extensions, call insert
}	

public void insert(File file)
{
      em.persist(file);
      em.flush();
}

public void addToQueue(List validFiles) throws WatcherException
{
   // iterate thru files
   //create a TextMessage using the file name
   //send the message
}
}


==================================
Fetcher.java

public class Fetcher 
implements MessageListener 
{

@Resource
private MessageDrivenContext context;

@PersistenceContext (unitName="WatcherDB")
private EntityManager em;
	
public void onMessage(Message arg0) {

     String fileName = ((TextMessage)arg0).getText();
     File remoteFile = (File)em.createQuery("from File where fileName=:filename").setParameter("filename",fileName).getSingleResult();

     //check disk space to make sure there is enough space to put the file
     transfer(remotefile,localfile);

     remoteFile.setStatus("COMPLETE");
     em.merge(remoteFile);
     em.flush();

     
}

public void transfer(File remoteFile, File localFile)
{
     remoteFile.setStatus("RUNNING");

     em.merge(remoteFile);
     em.flush();
}
     
}

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4129914#4129914

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4129914



More information about the jboss-user mailing list