-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Calling an EJB (Session Bean) from within a POJO method
PostPosted: Thu Jul 15, 2004 5:14 pm 
Newbie

Joined: Thu Jul 15, 2004 4:58 pm
Posts: 5
I have used Hibernate wrapped in a Session Bean under JBoss 3.2.5 and been using it successfully. However, I run into a problem, on the client side, when i call the same EJB from with a persistent class (POJO). I have narrowed it down to the fact that, i get the exception ONLY because of the presence of the narrow() statement in the Account (POJO) class. Why is that?

By the way, in case you are curious, I have made the Account class Serializable because I'm using Betwixt to print out the object contents in XML form for readability and debugging.

Following is the code of interest:

Code:
Account Session Bean: -----------------------------------------------
public class AccountDAOSessionBean implements SessionBean {

  protected Session hibernate;

  ...

  public Account find(long number) throws EJBException {
    log.debug("find(" + number + ")");
    try {
      if (!hibernate.isConnected())
        hibernate.reconnect();
      Query query = hibernate.getNamedQuery(Account.class.getName()
          + ".findByNumber");
      query.setLong("number", number);
      query.setBoolean("online", true);
      query.setBoolean("deleted", false);
      List list = query.list();
      if (list.isEmpty())
        throw new Exception("account " + number + " not found");
      return (Account) list.get(0);
    } catch (Exception e) {
      log.warn("could not find account " + number, e);
      throw new EJBException("could not find account " + number, e);
    } finally {
      try {
        hibernate.disconnect();
      } catch (Exception e) {
        log.warn("error closing hibernate session", e);
      }
    }
  }

  public List findChildren(Account account) throws EJBException {
    log.debug("getChildren(" + account.toShortString() + ")");
    try {
      if (!hibernate.isConnected())
        hibernate.reconnect();
      Query query = hibernate.getNamedQuery(Account.class.getName()
          + ".findChildren");
      query.setProperties(account);
      return query.list();
    } catch (Exception e) {
      throw new EJBException("error getting children for account " + this, e);
    } finally {
      try {
        hibernate.disconnect();
      } catch (Exception e) {
        log.warn("error closing hibernate session", e);
      }
    }
  }

  ...
}


Account POJO: ---------------------------------------------------------
public class Account implements Serializable {

  ...

  public List getChildren() {
    try {
      Object obj = new InitialContext().lookup("AccountDAO");
      AccountDAOHome accountDAOHome = (AccountDAOHome) PortableRemoteObject
          .narrow(obj, AccountDAOHome.class);
      //      return accountDAOHome.create().findChildren(this);
    } catch (Throwable e) {
    }
    return null;
  }

  ...
}


Client's main() method: ------------------------------------------------
153  public static void main(String[] args) throws Exception {
154    Context context = new InitialContext();
155    Object obj = context.lookup("AccountDAO");
156    AccountDAOHome accountDAOHome = (AccountDAOHome) PortableRemoteObject
157        .narrow(obj, AccountDAOHome.class);
158    AccountDAO accountDAO = accountDAOHome.create();
159    Account account = accountDAO.find(1517);
160    log.info(account);
161  }


Exception Thrown within client: -----------------------------------------
java.lang.reflect.UndeclaredThrowableException
   at $Proxy1.find(Unknown Source)
   at com.unisource.ec.ejb.account.AccountDAOSessionBean.main(AccountDAOSessionBean.java:159)
Caused by: java.io.InvalidClassException: com.unisource.ec.schema.account.Account; local class incompatible: stream classdesc serialVersionUID = 5464614373768493396, local class serialVersionUID = 7044260632390500770
   at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:463)
   at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1521)
   at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1435)
   at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1521)
   at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1435)
   at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1626)
   at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274)
   at java.io.ObjectInputStream.readObject(ObjectInputStream.java:324)
   at java.rmi.MarshalledObject.get(MarshalledObject.java:135)
   at org.jboss.invocation.jrmp.interfaces.JRMPInvokerProxy.invoke(JRMPInvokerProxy.java:136)
   at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:96)
   at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.java:46)
   at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:53)
   at org.jboss.proxy.ejb.StatefulSessionInterceptor.invoke(StatefulSessionInterceptor.java:104)
   at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:85)
   ... 2 more
Exception in thread "main"


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 15, 2004 9:36 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Are you sure you don't have different versions of the class file on client/server?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.