Hi,
I'm quite confused how Hibernate3 works in n-tier architecture.
Look at this real system example.
I have n-tier system. It's really quite big architecture with about 25 applications - ears. Some of this application uses Hibernate, some do not.
Let's considered application that is responsible for importing and serving data. It uses MDBs and Hibernate3 bulk operations (hundred of thousands of records) for importing data. One of application's functionality is to provide data reference and dictionaries services through EJBs.
This layer also uses Hibernate3 and CriteriaAPI to access database. It uses intensively lazy initialization either.
The next layer (applications) are services with a specific business logic. These are EJBs too, but they do not use Hibernate as a DAO.
As the result they receive ClassNotFoundException. Firstly the problem was with collections - implementation was Hibernate-specific. Secondly it appears that some hibernate classes are missing during deserialization - I'm quite sure that it is lazy initialization proxy classes.
How can I build appliaction using Hibernate3 and avoid dependency on this framework on other, not database-related tiers ? I can of course build DTO pattern around Hibernate and repack all of models in new REAL POJO models, but maybe Hibernate provides some functionalities out-of-the-box.
This code comes from
http://forum.hibernate.org/viewtopic.php?t=942572, but it looks like my proxy classes do not implements HibernateProxy interface. Moreover this solution is not recommended by Hibernate Team.
Code:
public class ProxyConverter {
public static Object convert(Object object)
{
if (object instanceof HibernateProxy) {
HibernateProxy proxy = (HibernateProxy) object;
LazyInitializer li = proxy.getHibernateLazyInitializer();
return li.getImplementation();
}
else {
return object;
}
}
}
Thanks for any solution...