Community

Classloader issue when persistence unit and ejb in different jars - how to solve?

created by Shri Shrimad in EJB 3.0 - View the full discussion

Hello,

 

For example, I have two jars:

 

1. JpaLib.jar, which contain entity class (for example, Account) and persistence unit JpaLibPU.

2. JpaBean.jar, which contain ejb3 SLSB, which uses TestPU to get Account from database.

 

 

{{{

@Stateless

public class JpaTestBean implements ...

{

    @PersistenceContext(unitName="JpaLibPU")

    private EntityManager em;

 

    public Account getAccount( String id )

    {

         return em.find( Account.class, id );

    }

}}}

 

 

After deploy, all works ok.

 

When I redeploy JpaLib.jar (add another entity class, for example), JpaBean.jar is stopped and started again, when JpaLibPU becomes available.

 

But, when I invoke getAccount I get exception: "java.lang.ClassCastException: tst.entity.Account cannot be cast to tst.entity.Account". As I understand, this happens due Account in JpaBean.jar and Account in JpaLib.jar loaded using defferent classloaders.

 

If I manually "touch" JpaBean.jar - jboss redeploy it and all works fine again.

 

How can I force JBoss to automatically redeploy (not just dtop/start) JpaBean.jar when JpaLib.jar is redeployed?

 

Any ideas?

Reply to this message by going to Community

Start a new discussion in EJB 3.0 at Community