Hibernate lazy loading simple solution

2010-10-03  来源:本站原创  分类:Java  人气:179 

Recently doing a project with a piece of data persistence layer hibernate. After the previous study used no how, has been in use IBATIS. When the integration of spring security encountered "no session, or session was closed", so look for good solutions on the Internet.

Should tend to be more common now is to configure opensessioninview, but this thing feels too much loss of performance, because after all, need to use lazy loading when those data are not many, we can say very little. Just for this and all of the session all the end of the request to keep the page is worth the candle.

Our aim is to configure the delay in loading for optimal performance when needed to query data, not the time not to query. Appears "no session, or session was closed" when the error should be that we need these data, when the data is empty. That hibernate in the session before closing to get the data you are not on it. We will generally be in the business logic written in the service, call the dao in the service method, service method to configure things.

In response to this, we can control the service method which hibernate, let it load the data.

For example:

public SecUser getUserWithRole (String userName) (
SecUser user = userDAO.getUser (userName);
if (user! = null) (
user.getRoleSet (). size ();// click here to directly call the size method permission set, so that role hibernate load data.
)
return user;
)

So that we can simply close the session to avoid the exception, and will not affect the hibernate for session management.

These are some personal thoughts, if there are problems Paizhuan heroes please correct me.

相关文章
  • Hibernate lazy loading simple solution 2010-10-03

    Recently doing a project with a piece of data persistence layer hibernate. After the previous study used no how, has been in use IBATIS. When the integration of spring security encountered "no session, or session was closed", so look for good so

  • hibernate lazy loading issue a temporary solution 2011-05-06

    hibernate lazy loading problems often plague us today, hibernate itself found to provide some solutions Hibernate.initialize (company.getUsers ()); This collection is loaded users But does not support recursive loading it is not guaranteed that the e

  • Discussion hibernate lazy loading 2010-10-01

    Hibernate lazy initialization error is the use of development projects in the most common mistakes. If the configuration of a class or collection of search strategy of delay, it must be when the agent or agent class instance is a collection of persis

  • Hibernate Lazy loading not fully realized due to OO 2010-06-02

    Transfer from: http://www.sulong.info/archives/335 Object and relational database fundamental difference exists between, ORM (object / relational mapping) tried to object mapping to relational database table structure, which simplifies storage object

  • hibernate lazy loading principles reproduced great ~ ~ 2008-11-12

    hibernate lazy loading of the principle of When using the load method of query session records in the database, we return a proxy object, rather than the needs of that object; for example, there is a Student table in the database, we have cn.binyulan

  • json-lib hibernate lazy loading problem 2010-10-07

    json-lib hibernate lazy loading problem ------ Question: Using json-lib to hibernate lazy loading of objects into a json when session closed packet error ------ Address: Can use json-lib's JsonConfig filter out unwanted properties, using the apply me

  • spring + hibernate lazy loading errors integrated solution 2010-11-25

    org.springframework.dao.InvalidDataAccessApiUsageException error org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.NEVER / MANUAL): Turn your Session into FlushMode.COMMIT / AUTO

  • hibernate lazy loading failed 2010-02-03

    Concerned about the javaeye has been more than a year, but had no opportunity to write a log. Today, they wanted big cow jokes are not afraid of you wrote a log. Want to beginners strtus, hibernate, spring who have some help. The lazy loading, I no l

  • Hibernate lazy loading mechanism 2009-09-18

    Lazy loading: Lazy loading mechanism is in order to avoid unnecessary performance overhead and put forward the so-called lazy loading is that when data in the real needs when we come to the real implementation of the data load operation. Provided in

  • BlazeDS & Hibernate lazy loading in n-tier arhitecture 2010-04-07

    Original link: 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: - Fle

  • Hibernate lazy loading FOR Class 2010-05-09

    lazy Policy can be used in : * <class> The label : Can the value true/false * <property> The label, you can value true/false, This feature requires class enhancement * <set>/<list> And so the collection, you can evaluate to true/fa

  • Hibernate lazy loading FOR Connection 2010-05-10

    Hibernate Collection property of lazy loading policy : In the collection properties, you can configure the lazy loading policy , A value of :true/false/extra true: The default value, which means that only the collection gets inside the element object

  • Hibernate lazy loading single-ended correlation FOR 2010-05-10

    Hibernate To load policy-Terminal associated lazy : That is, in <one-to-one>/<many-to-one> You can configure on the label Lazy loading policy . Can a value :false/proxy/no-proxy false: Cancel the lazy loading policy, that is, while loading the

  • Hibernate lazy loading 2010-05-10

    What is hibernate lazy load? The so-called lazy loading (lazy) is to delay loading, lazy loading. When to use lazy loading it? Can only be answered when to use lazy loading with lazy loading. Why should lazy load it? When we want to access the data t

  • Hibernate lazy loading in the load method and the principle of 2010-08-29

    When using the session method in load record in the database query, we return a proxy object, not really need that object; for example, there is a Student table in the database, we have cn.binyulan.doman.Student areas object, if the query Id is "2006

  • Detailed hibernate lazy loading problem 2010-10-03

    Lazy loading: Lazy loading mechanism is to avoid unnecessary performance overhead of their argument, the so-called lazy loading is when the really need the data before it will actually perform the data loading operation. Provided in the Hibernate obj

  • The hibernate lazy loading (Lazy Loading) 2011-01-07

    Avoid some cases, association brings unnecessary overhead, Hibernate introduced the concept of lazy loading; Hibernate3, can be recorded for the delay: Entity object Collection (Collection) Lazy property Through the Load method, the target entity obj

  • Spring + Hibernate lazy loading test base class 2009-08-13

    package cn.com.oneslife; import junit.framework.TestCase; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.junit.AfterClass; import org.springframework.context.ApplicationContext; import org.springframework.context.suppor

  • hibernate lazy loading Principle and Realization 2010-03-29

    Can read: http://superleo.javaeye.com/blog/243322

  • hibernate in the pessimistic and optimistic locking lock and lazy loading 2009-04-02

    hibernate frequently used when many individuals of the same data at the same time when changes will happen dirty data, resulting in data inconsistency, the solution can be adopted by the pessimistic and optimistic locking to achieve lock. Pessimistic