What is the code for the create and post create? What is the serverside exception? What is the primary key type?
-dain Peter Shillan wrote: > Hi there, > > I have a really simple bean and test for that bean. I'm building the test gradually. >I've included what I have so far. The problem is that although the bean is created, >findByPrimaryKey() never finds any beans and findAll() always returns 0. If I try to >create the bean again though, the bean is already there and a ServerException is >thrown. (BTW, why a ServerException? Should it not be a CreateException?). > > The error from the line: > > Message beanByPK = _home.findByPrimaryKey(new Integer(1)); > > is: > > [java] javax.ejb.ObjectNotFoundException: No such entity! > [java] at >sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:245) > [java] at >sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:220) > [java] at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:122) > [java] at org.jboss.invocation.jrmp.server.JRMPInvoker_Stub.invoke(Unknown >Source) > [java] at >org.jboss.invocation.jrmp.interfaces.JRMPInvokerProxy.invoke(JRMPInvokerProxy.java:128) > [java] at >org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:108) > [java] .F > [java] at >org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.java:73) > [java] at >org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:76) > [java] at >org.jboss.proxy.ejb.HomeInterceptor.invoke(HomeInterceptor.java:185) > [java] at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:96) > [java] at $Proxy0.findByPrimaryKey(Unknown Source) > > The error from the line: > > Message beanByPK = _home.findByPrimaryKey(new Integer(1)); > > is: > > 1) >testCreateMessageBean(client.uk.org.objectwiz.model.forum.ejb.TestClient)junit.framework.AssertionFailedError: > [TestClient.removeAllBeans()] number of beans: 0 > > But if I try to insert the bean again, the error is: > > [java] java.rmi.ServerException: RemoteException occurred in server thread; >nested exception is: > [java] javax.transaction.TransactionRolledbackException: INSERTING AN >ALREADY EXISTING BEAN, ID = 1; nested exception is: > [java] java.lang.IllegalStateException: INSERTING AN ALREADY EXISTING BEAN, >ID = 1 > [java] javax.transaction.TransactionRolledbackException: INSERTING AN ALREADY >EXISTING BEAN, ID = 1; nested exception is: > [java] java.lang.IllegalStateException: INSERTING AN ALREADY EXISTING BEAN, >ID = 1 > [java] java.lang.IllegalStateException: INSERTING AN ALREADY EXISTING BEAN, ID >= 1 > [java] .F > [java] at >sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:245) > [java] at >sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:220) > [java] at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:122) > [java] at org.jboss.invocation.jrmp.server.JRMPInvoker_Stub.invoke(Unknown >Source) > [java] at >org.jboss.invocation.jrmp.interfaces.JRMPInvokerProxy.invoke(JRMPInvokerProxy.java:128) > > Can anyone shed any light on this? > > Peter. > > - 8< - INCLUDED CODE - 8< - > > public class TestClient extends TestCase > { > private MessageHome _home; > > public static void main(String[] args) > { > junit.textui.TestRunner.run(TestClient.class); > } > > public TestClient(String name) > { > super(name); > } > > public void testCreateMessageBean() > { > try > { > Integer beanKey = new Integer(1); > _home.create(beanKey, "Test", "This is a test"); > > Message beanByPK = _home.findByPrimaryKey(new Integer(1)); > assertNotNull("[TestClient.testCreateMessageBean()] findByPrimaryKey(1) >returned null", beanByPK); > } > catch(Exception e) > { > e.printStackTrace(); > fail(); > } > } > > protected void setUp() throws Exception > { > // Get a naming context > InitialContext jndiContext = new InitialContext(); > > // Get a reference to the message bean > Object ref = jndiContext.lookup("ejb/forum/Message"); > > // Get a reference from this to the bean's Home interface > _home = (MessageHome) PortableRemoteObject.narrow(ref, MessageHome.class); > } > > protected void tearDown() throws Exception > { > try > { > removeAllBeans(); > } > catch(Exception e) > { > e.printStackTrace(); > } > } > > /** > * Remove all beans > */ > private void removeAllBeans() throws Exception > { > Collection allBeans = _home.findAll(); > > assertTrue("[TestClient.removeAllBeans()] number of beans: " + allBeans.size(), >allBeans.size() > 0); > > Iterator allBeansIterator = allBeans.iterator(); > > while(allBeansIterator.hasNext()) > { > Message bean = (Message)allBeansIterator.next(); > _home.remove(bean.getHandle()); > } > } > } > > - >8 - INCLUDED CODE - >8 - > > ________________________________________________________________________ > > E-mail is an informal method of communication and may be subject to data corruption, >interception and unauthorised amendment for which Digital Bridges Ltd will accept no >liability. Therefore, it will normally be inappropriate to rely on information >contained on e-mail without obtaining written confirmation. > > This e-mail may contain confidential and/or privileged information. If you are not >the intended recipient (or have received this e-mail in error) please notify the >sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or >distribution of the material in this e-mail is strictly forbidden. > > ________________________________________________________________________ > > > _______________________________________________ > JBoss-user mailing list > [EMAIL PROTECTED] > https://lists.sourceforge.net/lists/listinfo/jboss-user > _______________________________________________ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user