finder exception is not thrown
elich11 Aug 25, 2004 4:39 AMa finder exception is not thrown when we use a finder that returns a collection (FindByName), we can see in the test that the collection is empty. also the findByPrimaryKey works fine (exception is thrown)
this is the test code:
package messaging_as.domain;
import java.util.Date;
import javax.ejb.CreateException;
import javax.ejb.EJBException;
import javax.ejb.FinderException;
import javax.ejb.RemoveException;
import junit.framework.Test;
import junit.framework.TestSuite;
import messaging_as.service.util.EJBHomeFactory;
import net.sourceforge.junitejb.EJBTestCase;
import org.apache.log4j.Category;
/**
*
* <p>Title: </p>
* <p>
* </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author elih
* @version 1.0
*/
public class FinderExceptionTest
extends EJBTestCase {
private Category _log = Category.getInstance(getClass());
private TestCmpHome _testCmpHome = null;
private TestCmp _testCmp = null;
private boolean finderExceptinFlag = false;
public static Test suite() {
TestSuite testSuite = new TestSuite("FinderExceptionTest");
testSuite.addTestSuite(FinderExceptionTest.class);
return testSuite;
}
public void setUp() throws Exception {
_testCmpHome = (TestCmpHome) EJBHomeFactory.getFactory().
lookUpHome("TestCmpLocalHome");
}
public void tearDown() throws Exception {
}
public FinderExceptionTest(String name) {
super(name);
}
public void testFinderException() {
_log.info("testFinderException");
try {
_testCmpHome.create(new Integer(1), "testCmp");
_testCmpHome.create(new Integer(2), "testCmp");
java.util.Collection cmps = _testCmpHome.findByName("testCmp");
System.out.println("after creation cmps.isEmpty(): " + cmps.isEmpty());
}
catch (CreateException ex) {
ex.printStackTrace();
}
catch (Exception e) {
e.printStackTrace();
}
try {
_testCmp = _testCmpHome.findByPrimaryKey(new Integer(1));
_testCmp.remove();
_testCmp = _testCmpHome.findByPrimaryKey(new Integer(2));
_testCmp.remove();
}
catch (RemoveException ex1) {
ex1.printStackTrace();
}
catch (EJBException ex1) {
ex1.printStackTrace();
}
catch (Exception e) {
e.printStackTrace();
}
try {
java.util.Collection cmps = _testCmpHome.findByName("testCmp");
//_testCmpHome.findByPrimaryKey(new Integer(1));
System.out.println("after delete cmps.isEmpty(): " + cmps.isEmpty());
}
catch (FinderException ex2) {
finderExceptinFlag = true;
_log.info("FinderException.");
}
assertTrue(finderExceptinFlag);
}
}
snippet from ejb-jar.xml:
<entity> <display-name>TestCmp</display-name> <ejb-name>TestCmp</ejb-name> <home>messaging_as.domain.TestCmpRemoteHome</home> <remote>messaging_as.domain.TestCmpRemote</remote> <local-home>messaging_as.domain.TestCmpHome</local-home> <local>messaging_as.domain.TestCmp</local> <ejb-class>messaging_as.domain.TestCmpBean</ejb-class> <persistence-type>Container</persistence-type> <prim-key-class>java.lang.Integer</prim-key-class> <reentrant>False</reentrant> <cmp-version>2.x</cmp-version> <abstract-schema-name>TestCmp</abstract-schema-name> <cmp-field> <field-name>id</field-name> </cmp-field> <cmp-field> <field-name>name</field-name> </cmp-field> <primkey-field>id</primkey-field> <query> <query-method> <method-name>findByName</method-name> <method-params> <method-param>java.lang.String</method-param> </method-params> </query-method> <ejb-ql>SELECT OBJECT(u) FROM TestCmp as u WHERE u.name = ?1</ejb-ql> </query> </entity> <entity>