Hi Angelo,

The MyCreate service creates a new record, but doesn't commit until
after MyThread is started.

The MyThread service automatically gets a different Hibernate Session,
and thus can't see the record that hasn't been committed yet by the
other session.

I'm not that familiar with MySQL, but my guess is that the InnoDB engine
supports transactions, while the MyISAM engine doesn't?

If you want this record to be visible across two different threads, you
must commit before you start the second thread.  Or perhaps it's simpler
not to use a second thread, and do everything in one session.

Andy

On Wed, 2008-02-06 at 22:33 -0800, Angelo Chen wrote:
> Hi,
> 
> I have two services, namely MyCreate and MyThread, what they do is:
> 
> MyCreate will append a new record using Tapestry-Hibernate's session and
> MyThread will look it up, MyThread is in a thread while MyCreate is not, the
> problem is, the newly created record can not be located by MyThread, if
> MyThread is called as non-threaded service, everything works.
> 
> Also if the table type is MyISAM, the threaded service works too, it only
> comes out when the type is InnoDB, any ideas? here is the code:
> 
> 
> // page
> 
>   @Inject
>   private MyCreate create;
>   @Inject
>   private MyThread myThread;
> 
>   Object onSuccess() {
>       final Long id = create.append();
>       new Thread(new Runnable() {
>           public void run() {
>             myThread.findMe(id);
>           }
>       }).start();
>       return null;
>   }
> 
> // services
> 
> public class MyCreateImpl implements MyCreate {
> 
>     final private Session session;
>     public MyCreateImpl(Session session) { this.session = session;}
> 
>     public Long append() {
>         Usr usr = new Usr();
>         usr.setName("test");
>         session.save(usr);
>         return usr.getId();
>     }
> }
> 
> public class MyThreadImpl implements MyThread {
> 
>     final private Session session;
>     final private ThreadCleanupHub threadCleanupHub;
> 
>     public MyThreadImpl(Session session, ThreadCleanupHub threadCleanupHub)
> {
>         this.session = session;
>         this.threadCleanupHub = threadCleanupHub;
>     }
> 
>     public void findMe(Long id) {
>         System.out.println(id);
>         Usr u = (Usr) session.get(Usr.class, id);
>         if (u != null)
>             System.out.println("found " + u.getName());
>         else
>             System.out.println("not found2");
>         threadCleanupHub.cleanup();      
>     }
> }


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to