0 Replies Latest reply on Mar 2, 2006 12:52 PM by dhinojosa

    Inconsistent result with removal of entity beans

    dhinojosa

      I have one bean called Resource that has a blob, but other than that there is nothing special about it.

      I have another bean called StandardProduct that is subclass of a Product POJO there are some eager clobs with it. Other than that there is nothing special about it either.

      When I run my test harnass on my session facade that manages these, I get a different result when I try to remove each of these entity beans.

      For my Resource Facade, here is my test code:

       public void testCrud() {
       try {
       Resource resource = new Resource();
       Date date = new Date();
       byte[] data = new byte[]{4,3,2,1,2,3,4,6,13};
       String description = "description";
       String mimeType = "img/gif";
       String name = "name.gif";
       String notes = "notes";
      
       resource.setByteArray(data);
       resource.setCreatedDate(date);
       resource.setDescription(description);
       resource.setMimeType(mimeType);
       resource.setName(name);
       resource.setNotes(notes);
       resource.setUpdatedDate(new Date());
      
       InitialContext ctx = getInitialContext();
      
       ResourceFacadeLocal local = (ResourceFacadeLocal)
       ctx.lookup("ResourceFacadeBean/local");
      
       local.create(resource);
      
       resource = local.findByPrimaryKey(resource.getId());
       assertEquals(date, resource.getCreatedDate());
       assertEquals(date, resource.getUpdatedDate());
       ArrayAssert.assertEquals(data, resource.getByteArray());
       assertEquals(description, resource.getDescription());
       assertEquals(mimeType, resource.getMimeType());
       assertEquals(name, resource.getName());
       assertEquals(notes, resource.getNotes());
      
       String newDescription = "New Desciption";
       resource.setDescription(newDescription);
      
       local.update(resource);
       resource = local.findByPrimaryKey(resource.getId());
       assertEquals(newDescription, resource.getDescription());
      
       local.remove(resource);
       resource = local.findByPrimaryKey(resource.getId());
       assertNull(resource);
       } catch (Throwable e) {
       e.printStackTrace();
       fail(e.getMessage());
       }
       }
      


      If you notice that as one of the last items there I have assertNull(resource), this tests and resolves to true and all is well.

      Testing for a StandardProduct Facade, I do almost the same thing.
       public void testSimpleStandardProduct() {
       try {
       InitialContext ctx = getInitialContext();
      
       StandardProductFacadeLocal local = (StandardProductFacadeLocal)
       ctx.lookup("StandardProductFacadeBean/local");
      
       StandardProduct standardProduct = new StandardProduct();
       setSampleValues(standardProduct);
      
       local.create(standardProduct);
       assertNotNull(standardProduct.getId());
       standardProduct = local.findByPrimaryKey(standardProduct.getId());
      
       assertEquals(true, standardProduct.getAvailable());
       assertEquals(true, standardProduct.getCallForPrice());
       assertEquals(sampleDate, standardProduct.getCreatedDate());
       assertEquals("description",standardProduct.getDescription());
       assertEquals(12.0f ,standardProduct.getHeight());
       assertEquals(12.0f ,standardProduct.getLength());
       assertEquals("foo" ,standardProduct.getName());
       assertEquals("notes" ,standardProduct.getNotes());
       assertEquals(143.00f ,standardProduct.getPrice());
       assertEquals("subtype" ,standardProduct.getSubtype());
       assertEquals("type" ,standardProduct.getType());
       assertEquals(124.00f,standardProduct.getUpcharge());
       assertEquals(sampleDate,standardProduct.getUpdatedDate());
       assertEquals("http://www.cool.com",standardProduct.getUrl());
       assertEquals(144.00f,standardProduct.getWeight());
       assertEquals(122.00f ,standardProduct.getWidth());
      
       standardProduct.setName("bar");
       local.update(standardProduct);
       assertNotNull(standardProduct.getId());
       standardProduct = local.findByPrimaryKey(standardProduct.getId());
      
       assertEquals("bar", standardProduct.getName());
      
       local.remove(standardProduct);
       standardProduct = local.findByPrimaryKey(standardProduct.getId());
       assertNull(standardProduct);
       } catch (NamingException ne) {
       ne.printStackTrace();
       fail("NamingException thrown" + ne.getMessage());
      
       } catch (Throwable e) {
       e.printStackTrace();
       fail("Exception thrown" + e.getMessage());
      
       }
       }
      


      The difference now is that I get:
      javax.ejb.EJBException: javax.persistence.NoResultException: No entity found for query
       at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:69)
       at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:83)
       at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:192)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
      



      Both results make sense, but they are inconsistent. Is there something I am not understanding about the spec? or is this a problem. I must include that before this I received a ClassNotFound ANTLR/ANTLRException.