Spring Boot : Detaching Queued Operation - spring

In spring boot when I tried save any data it gives
: HHH000496: Detaching an uninitialized collection with queued
operations from a session
I have already tried adding #Transitional keyword but it did not work.Is there any suggestion for this issue?

Related

Spring DevTools persistent session empty session map

I am trying to make Spring session persistence work but so far no luck.
So I start the app, do log in, change Java code to force restart and session is lost after that.
Enabled session persistence using server.servlet.session.persistent=true.
I see this property is picked up, and Tomcat is configured properly.
After some debugging I found out that the doUnload() method in org.apache.catalina.session.StandardManager is called properly but the session map is empty!
This happens in https://github.com/Oreste-Luci/apache-tomcat-8.0.26-src/blob/05aeff976f6a75346c95cf6d3a9c8add8b9cb0bc/java/org/apache/catalina/session/StandardManager.java#L338.
Any idea why this is happening? I did log in so I expect session to be created...
Spring Boot 2.1.1.RELEASE, Tomcat started at same version

Check MongoDB Status with Spring Boot

How do I check, if the connection to the MongoDB is active (without using the actuator project) if just a MongoRepository is used, which hides the connection?
If mongodb connection is inactive then spring boot application will throw errors which can be checked in logs.
Ideally actuator project is best way to check the status.
You can also check the status by creating your own controller method lets say ping and in implementation write some operation like MongoRepository.findAll() if it returns positive value it is in active state.

Initializing tables on spring boot startup

I have a spring boot application, in which I need to initialize the tables based on some configuration. I am using managed transactions using #Transactional. My problem is that I do not know when app is ready to make DB transactions.
I created a bean which reads the configuration and updates the tables, but it gets an exception at that point:
Could not obtain transaction-synchronized Session for current thread
I have tried that if I wait sprintboot to start and make the same transactions through HTTP requests, then there is no problem. So it seems to be a timing problem. I have also tried moving the code to #PostConstruct of bean but it does not fix the issue.
How can I know that app is ready for DB transactions? Any help will be much appreciated.
You can listen on some events Spring is publishing.
See here
You properbly need to listen on this even: ContextRefreshedEvent
The simplest and cleanest way of performing the initialization should be by making your bean implement ApplicationListener for ContextRefreshedEvent and then handling the initialization in the onApplicationEvent method. This way, your initialization will run when Spring's whole application context is initialized

Spring Application Context Initialization

In my Spring Application, at the time of context Initialization. The DB is not available, it will come up after some time (Due to DB redundancy). In this scenario, my spring application initialization should be delayed or the application should do retry for DB connectivity. How to achieve the same via Spring.
Srirama.
I'd suggest investigating the ApplicationContextInitializer. It is meant to be used for setting up your context before most of the magic of spring initialization happens.
I'm not sure if it is designed for your use case, but no beans are initialized when the initialize method is called during startup.
The example provided in the link deals with properties, but I see no reason why you should not create your own manually created connection and wait for it's readiness.
Thanks for the reply.
My application is initialized by means of C3P0. Here C3P0, is trying to reconnect to DB only for 30 times (the default configuration for acquireRetryAttempts) and after that it is saying failed to create the application beans.
Changed the configuration for acquireRetryAttempts to -1, so that C3P0 is retrying indefinitely till the DB connection is successful. Basically my app. initialization should be delayed till the DB comes up.
Srirama.

How to clear spring webflow scope data on exiting the application by simply closing the browser?

Details:-
Application is developed using Spring webflow 2.1.1 and Spring core framework.
Spring webflow acts as a MVC controller for application
Application is storing lot of data in spring webflow flowscope variables which is rendered on UI using jsf richfaces.
For same application in web.xml session timeout is configured to 120 minutes.
Problem is when browser is closed in between of webflow OR http session is timed out , what happens to data stored in spring webflow flowscope ? It is observed that end state is not called in both scenario. Does that data reside on Java Heap ?
Also as per memory analyser tool, 70% of heap is consumed by webAppServletContext.
Currently application has out of memory issues even after increasing the heap to 3GB.
Spring WebFlow uses HttpSession to store all its contextual information. As long as Servlet Container invalidates/destroys user associated HttpSession, all Spring WebFlow stored variables become destroyed too (well, can be garbage collected).
If you're having memory problems check your Servlet Container settings. Some have mechanisms like a periodic job to clean expired HttpSession, some others clean upon an invalid request, etc...
Anyway, you'll unlikely reach an OutOfMemoryError because of the described mechanisms, as it will show defective Servlet implementation.

Resources