0

Good Evening, i have an exception called org.hibernate.LazyInitializationException: could not initialize proxy - no Session it rises when i tries to get attributes from an ibject thta resides in the session, here's my JSP stmts that get parameters from session attributes:

    <c:forEach items="${product_list}" var="car">
                <tr>
                    <td><INPUT type="checkbox" name="chk_group"
                        value="${car.carId}" /></td>
                    <td><c:out value="${car.carId}" /></td>
                    <td><c:out value="${car.model.modelName}" /></td>
                    <td><c:out value="${car.model.modelId}" /></td>
                    <td><c:out value="${car.carDesc}" /></td>
                    <td><c:out value="${car.quantity}" /></td>
                    <td><c:out value="${car.price}" /></td>
                    <td><c:out value="${car.enginCc}" /></td>
                    <td><c:out value="${car.trans}" /></td>
                    <td><c:out value="${car.noOfCylinder}" /></td>
                    <td><c:out value="${car.topSpeed}" /></td>
                    <td><c:out value="${car.fuelType}" /></td>
                    <td><c:out value="${car.fuelCapacity}" /></td>
                    <td><img src="pics/12234674066d64TK.jpg" class="Edit"
                        onclick="updateCar('product_table')"></td>

                </tr>
            </c:forEach>


<c:forEach items="${Search_Results}" var="search_result">

            <tr>
                <td><INPUT type="checkbox" name="chk_group"
                    value="${search_result.carId}" /></td>

                <td><c:out value="${search_result.carId}" /></td>
                <td><c:out value="${search_result.model.modelName}" /></td>
                <td><c:out value="${search_result.model.modelId}" /></td>
                <td><c:out value="${search_result.carDesc}" /></td>
                <td><c:out value="${search_result.quantity}" /></td>
                <td><c:out value="${search_result.price}" /></td>
                <td><c:out value="${search_result.enginCc}" /></td>
                <td><c:out value="${search_result.trans}" /></td>
                <td><c:out value="${search_result.noOfCylinder}" /></td>
                <td><c:out value="${search_result.topSpeed}" /></td>
                <td><c:out value="${search_result.fuelType}" /></td>
                <td><c:out value="${search_result.fuelCapacity}" /></td>
                <td><img src="pics/12234674066d64TK.jpg" class="Edit"
                    onclick="updateCar('Search_Table')"></td>

            </tr>
        </c:forEach>

Note: these exception is thrown only when i added the second for loop in my JSP, everything is clear without the second for loop !! please i want to know what these foor loop had make and how to overcome that

Eslam Hamdy
  • 7,126
  • 27
  • 105
  • 165
  • I think it does what it says on the tin - you have no `Session`. – Boris the Spider Mar 08 '13 at 17:09
  • How is Search_Results populated? If you put a debug breakpoint at the top of the 2nd loop, what's in the Search_Results collection? Just looking at what you've provided, my *guess* is that Model is a stub proxy object and the exception is happening when you try and call the getter for modelName. You also tagged open-session-in-view... are you using that filter? Is it working for other pages? – Gojira Mar 08 '13 at 17:09
  • i googled for that problem and someone said that these problem occured because the seesion is closed after the first request and you should use the open_session_in_view pattern to overcome that, but i don't know how to do that! – Eslam Hamdy Mar 08 '13 at 17:15
  • model is just a property(object) inside every instance in my collection, what do you mean by "Model is a stub proxy object and the exception is happening when you try and call the getter for modelName" ? – Eslam Hamdy Mar 08 '13 at 17:17
  • That someone was right ;-). Are you using pure Hibernate? Or Spring/Hibernate. You could write your own OpenSessionInView filter, but you can also use Spring's right out of the box (there may be others as well...). There's lots of help available on configuring that filter if you go the Spring/Hibernate route. For example... http://stackoverflow.com/questions/8435034/configuring-opensessioninviewfilter-with-spring-3-and-servlet-3. – Gojira Mar 08 '13 at 17:19
  • The way Hibernate lazy loading works (I am *vastly* simplifying here) is that instead of fully populating the entire object graph, it creates "stub" proxies for member variables with just the object's identifier populated and no other information from the database. You may think you're calling a getter on the model, but what Hibernate has cleverly done in the background is replace your model with a "stub" model that just has the ID and not the name, etc. I'm happy to take this conversation into 'chat' if you would like to continue... SO generally prefers the comments don't get too long. – Gojira Mar 08 '13 at 17:22
  • ok i understand you but why it successeds in the first forloop and fails in the second? by the way i'am using pure hibernate V3.5 – Eslam Hamdy Mar 08 '13 at 17:26
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/25856/discussion-between-gojirademonstah-and-eslam) – Gojira Mar 08 '13 at 17:54

0 Answers0