[jboss-user] [EJB 3.0] - Re: eager vs. lazy fetching

amitvk do-not-reply at jboss.com
Mon Feb 4 14:17:45 EST 2008


Another way I found useful was using the OOP concepts to load the mappings or just the core table vlaues.

Have the main table mapped in the superclass and the mappings that you want to load sometimes in the subclass. 

e.g. If the table name is Customer.

have 2 entities Customer, and CustomerWithMapping
CUstomerWithMapping extends Customer.

Define all the Customer column values in Customer base class.

Define all the lazy mappings in CustomerWithMapping class with EAGER fetch..

If you just want to get the core table data find on the Customer. If you want it with mappings call e.g. Select e from CustomerMapping where e.CustomerNumber =1.

I used the Customer class when I want to display list of customers and CustomerWithMapping when working on a specefic Customer.

Hope this helps.

P.S the only problem I found was that you cannot use em.find to get the CustomerWithMapping Object as it tries to load the superclass.
In that case use JPQL -  Select e from CustomerMapping where e.CustomerNumber =1

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4126325#4126325

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4126325



More information about the jboss-user mailing list