`
hehailin1986_163.com
  • 浏览: 151184 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

BlazeDS & Hibernate lazy loading in n-tier arhitecture

    博客分类:
  • Flex
阅读更多
原文链接:http://forum.springsource.org/showthread.php?t=71622

Hi,

We have faced an issue on lazy loading Domain Objects with Hibernate in n-tier architecture with Spring BlazeDS.

Our architecture is just a basic Spring architecture model:

- Flex Client

- Web layer (includes BlazeDS configuration)
- Service layer
- HIbernateDAO+Domain model

For example, if we want to load this domain object
// example...
public class Customer {
  private List<Order> orders;
  private Address address
  // getters & setters
}


Orders and Address -fields are marked with lazy fetch. So when we simply load Customer, orders aren`t loaded at the same time, they are just Hibernate proxies. Hibernate session is closed after DAO layer.

Service layer gets the Customer object from DAO layer. Flex client requests the service layer method with some parameters trough BlazeDS and service layer returns the Customer to Flex.

And now comes the problem: lazyInitException.

After some searching and googling we founded out this: BlazeDS doesn`t recognize lazy fields (Hibernate proxies) and gives the error.

Possible solutions were:
a) change your architecture so, that you can use Open Session View Pattern
b) mark all lazy fields (Hibernate proxies) to null on service layer
c) use the Data Transfer Object anti-pattern: do not return any domain object to Flex, create matching DTO`s (for example CustomerDTO) and transform your domain objects to DTO on service layer.


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics