Database Entries in Spring

I am new to Spring and I would like to know a little more about sessions. I matched an obsolete database with annotated Hibernate objects and created several service objects for extraction, extraction, etc. My entities also contain other objects (mapped via foreign keys) and sets of objects. When I cross the entitiy schedule in my services, I have no problem. My services were wrapped in a TransactionProxyFactoryBean, so everything should be fine.

So, in my view controller, I request a bunch of entities from services. But when I cross the entity diagram in the view controller (for example, to display the name of the state of the user’s state, with the state and country being lazy loaded objects), the Hibernate session is already closed, and I get a “LazyInitializationException: it is impossible to initialize the proxy server, no session”

I would not want my services to willingly retrieve data that will consume a lot of memory, because my graphs are deep and may even have circular links. I also do not want to explicitly touch on the parts that I will show in the services, as this will mean that I will have to copy / paste such services again and again. Therefore, I want the Hibernate session to still be open when I am in the view controller, and not close the session until the view is shown. What can I do to open it?

My bean view looks like this: is there a way I can embed my TransactionProxyFactoryBean bean code in it?

  <bean name="/" class="example.SimpleViewController">
    <property name="userService" ref="userService"/>
    <property name="catalogService" ref="catalogService"/>
  </bean>

Greetings

Nick

+1
source share
2

. : Spring jpa/hibernate, , ?

Hibernate Spring, 100% Spring Session, , , Interceptor. JPA - , , . , , Spring .

+1

open-session-in-view, , , Spring; Spring , Struts JSP.

0

Source: https://habr.com/ru/post/1731448/


All Articles