Hi everyone,

   Sorry for posting this problem on the dev user list but i posted this on 
the JBoss forum and the JBoss user mailing list but didn't get any reply. And 
am i in urgent need to fix this problem. Have posted this under 
Database, Persistence and JBossCMP forum.

According to the ejb-spec "the container should must first synchronize the 
state of the entity bean instances that are participating in the same 
transaction context as the ejbFind." It seems that this was fixed in JBoss 
version 2.4.0 Bug No : 433115.
 I am using version 2.4.3 final release and still having problems with a 
finder invoked on a entity which has been modified in the same transaction 
context. I have written a small test in which i access an entity through a 
stateless session bean. The session bean modifies the entity instance and 
then calls a finder on the entity type. The updated record is not a part of 
the finder. If i get the spec right then the ejbStore should have been called 
on the entity instance and the updated entity should have been a part of the 
return from the finder method. But thats not the case. May be i am missing 
something can somebody point me in the right direction. 

Os: Red Hat Linux ver 6.2 
Sun's JDK 1.3 Database: Postgresql 7.1

Attaching the entity bean, session bean and the unit test for reference.

Thanx in advance.

Relevant bits of the code.

Entity class
========
public abstract class TestUserEjb implements EntityBean
{
    /**
     * Ejb Create methods
     * @param id The Id of the user 
     * @param name Name of this user
     * @param country Country of this user 
     * @throws CreateException if we are having problem creating the testuser
     * @return The testuser
     * @ejb:create-method
     */
    public TestUserPK ejbCreate(long userId, String name, String country)
        throws CreateException
    {
        setId(userId); // Id is the Pk
        setCountry(country);
        setName(name);
                
        return null;
    }
    //.....And the setters and the getters for the Entity
}

Stateless Session class method
=======================
    /**
     * @ejb:interface-method view-type="remote"
     */
    public void tryFinder(long userId) throws Exception
    {
        System.out.println("The newly created Id: " + userId);
        
        TestUserPK testPk = new TestUserPK(userId); 
        TestUserLocalHome testHome  = (TestUserLocalHome) 
            getLocalHome("TestUser");
        TestUserLocal testLocal = testHome.findByPrimaryKey(testPk);

        System.out.println("Before Updating");
        testLocal.setCountry("UK");
        System.out.println("After Updating");

        // The ejbStore method should get called before this....but is not 
getting called.        
        Collection coll = testHome.findByCountry("UK");
        System.out.println("After findByCountry()");
        
        Iterator it = coll.iterator();
        while (it.hasNext())
        {
            TestUserLocal local = (TestUserLocal) it.next();
            System.out.println("Id: " + local.getId() + " User country" 
                               + local.getCountry());            
        }
    }

Unit Test method
=============
    public void testEjbFinder()
    {
        try
        {
            // Create test user.
            long userId = createUser(new Random().nextInt(10), 
"User0","Australia");
            
            TestUserManagerHome userMgrHome = (TestUserManagerHome)
              
PortableRemoteObject.narrow(getContext().lookup("TestUserManager"),
            TestUserManagerHome.class);
            
            userMgrHome.create((long) 1).tryFinder(userId);
        }
        catch (Exception e)
        {
            e.printStackTrace(); 
        }
    }   

Sachin Pandey
Nuix Pty Ltd
(61)(02) 92839010

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to