I Managed to find an error (Bug) in
https://github.com/spring-projects/spring-session
Due to the fact that the project is poorly configured.
I set up that all sessions are saved in the database through the config: #EnableJdbcHttpSession in Mysql (MariaDB).
The trouble is that the filter is one for all and any request to the front ... for example, give the statics (picture, css, etc.) - it has its own session key and also climbs into the database.
Everyone getting the picture.
Any request from the front in which there is a session and the cuckolds goes to the Mysql.
Requests that do not need to go to the database go there.
This is a large number of SELECT .... UPDATE ... table calls
SPRING_SESSION
SPRING_SESSION_ATTRIBUTES
How would this error be described to the developers?
How to configured spring session with EnableJdbcHttpSession and filter ?
Only business request went to the database ?
Related
I'm working on a system where things can and will change outside of JPA, so I need a new session for every request, but my JavaEE app deployed into TomEE persists sessions between requests, resulting in entities that are cached when they've since been updated somewhere outside of the app.
I attempted to create a cfg.xml and get the session factory that way, but was just met with exceptions. I also attempted to unwrap the entity manager class to get the factory that way, but got an exception saying the class couldn't be unwrapped. I feel like this may be something to do with how TomEE and Hibernate interact. Are there issues with my current setup. Or am I trying to implement session-per-request wrong,
The problem that you have is not with the session, it is related with the session cache, so what you can do is invalidate your session cache:
session.refresh(entity)
then hibernate will compare database data and entity object data if there are differences then it will execute again an sql query.
session.clear()
will remove everything from the session cache, so you will not get old data.
So I have a maven / spring application running on tomcat 8. I'm playing around with storing the sessions in dynmao db. There are a few reasons why I want to do this but i'll spare you the details.
I've been following this guide pretty religiously https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/java-dg-tomcat-session-manager.html#java-dg-tomcat-sess-manage-with-ddb but my data does not seem to be being sent to the dynamoDB table I set up.
So what i've done.
First I downloaded this jar:
aws-dynamodb-session-tomcat-2.0.4.jar
and moved it to my lib folder.
Then I set up my context.xml like:
className="com.amazonaws.services.dynamodb.sessionmanager.DynamoDBSessionManager"
awsAccessKey="mykey"
awsSecretKey="mysecertKey"
regionId="us-east-1"
createIfNotExist="true" />
These apps are on EC2 instances so I skiped the ECB step. Next I set up a DBB table that looks like:
Table name Tomcat_SessionState
Primary partition key sessionId (String)
But when I restart my app and try and login I don't see anything geting posted there..
I've been tailing my catalina.out but no luck there either. Another note on this I don't see anything about DBB in my catalina.out strange.
Am I missing a common step here?
UPDATE:
When I start my app it creates the needed table. Just can't seem to get it to send the session id's out there. I wonder if a code change needs to be made to support this feature? I thought it supported any forum of sessions.
Edited by: dennis93 on Mar 8, 2018 2:13 PM
I see something like this in my log:
dynamo-session-manager-expired-sesion-reaper
Dynamo DB Tomcat Session Management Support is dropped. Ref: https://forums.aws.amazon.com/thread.jspa?threadID=275425
When I was experimenting with the AWS DynamoDB session manager, I experienced an unexplainable effect where writes of session data into DynamoDB would ONLY occur if the Manager is declared inside the global context.xml, i.e. within $CATALINA_HOME/conf/context.xml
The data has to be written to your DynamoDB table in order to persist across tomcat process restarts.
My application is as follows:
Spring 4, Spring MVC, Spring Data JPA, Hibernate 5.0.12
DB2 as database
Websphere 16 as server
Also is my web application multi-tenant based on schema. The implementation is almost like this: http://stuartingram.com/2016/10/02/spring-boot-schema-based-multi-tenancy/
Everything is working fine with multi-tenant when a user does CRUD operations on entities but when I try to seed some data on startup (ContextRefreshedEvent) the data is not inserted to the schemas.
But a previous request if data is in there, gives the right results that no data is there. I need to add here that one schema has already the seeded data.
The procedure is as follows:
Set tenant and with this the schema of the database
check if repository count is 0
if this is the case, create a new entity
save the new entity
The result of point 1 is correct, and there is no exception when the entity is saved (3). But there is no data in the database after the seeding.
Also is the tenant and schema correctly set before the repository methods are called.
A normal saving after the startup in a schema is successful.
What could be the reason why saving data to different schemes is not working before the application started completely?
Edit:
I tested the Code also on a Tomcat 8.5.4 and it is working. So there is something different in the implementation concerning WebSphere in Spring/Hibernate I guess.
I am using Turbine 2.3.2 with Hibernate 3. My problem is that the Hibernate session is not active when my (Velocity 1.6.4) template is executed, and I am accessing data from the database for which Hibernate needs lazy initialization. Therefore I get a LazyInitializationException - no Session error.
Since I want my Hibernate session to be alive when a velocity template executes I would like to have a class to execute after and before the Velocity template. This way I could open and close my Hibernate session at one place. (Disabling lazy initialization in Hibernate is not an option for me). Are there any possibilities related or not to Turbine to write a kind of listener or a filter (I am not sure how to call it) that would execute right before and after a Velocity template has been executed? Or maybe the servlet container could filter requests .... What option would you recommend?
Try looking at the Spring OpenSessionInViewFilter. It opens the Hibernate Session and assigns it to a threadlocal. That way, you can pick it up in your data access layer and use it.
Open Session in View is not a clean solution. You can configure in your criteria (if you use it) which association paths Hibernate has to eagerly fetch.
If you use HQL, just "touch" the association while the session is still open.
Your question seems to be about the (in)famous Open Session In View (OSIV) pattern.
Have a look at the Open Session in View page on the JBoss wiki, you'll find a filter based implementation (non Spring based).
I have a struts 2 application and a toplink persistence provider running on tomcat 6.0.20 and a MySql 5.1.38 server on a GNU/Linux machine. After committing the data the when i go to retrieve it the data it has disappeared from the database.
I do a em.commit() and em.flush() after my queries have executed. How do they disappear? I am using all standard configuration files. I have reduced the wait_timeout and the interactive_timout period in mysql. Also am using autoReconnectforPools in my persistence.xml.
I also invalidate the cache on every users logout.
Any ideas?
anyway it does not matter, the problem was solved by removing softweak from persistence.xml's entity type declaration and adding hardweak in its place.