<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Raphael Militani on Medium]]></title>
        <description><![CDATA[Stories by Raphael Militani on Medium]]></description>
        <link>https://medium.com/@raphaelmilitani?source=rss-f7ec74a31984------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Pahrnqw0RNZzQSQ5PFncYg.jpeg</url>
            <title>Stories by Raphael Militani on Medium</title>
            <link>https://medium.com/@raphaelmilitani?source=rss-f7ec74a31984------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 07:55:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@raphaelmilitani/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Changing the object type stored by Spring Session]]></title>
            <link>https://medium.com/@raphaelmilitani/changing-the-object-type-stored-by-spring-session-78385438aba3?source=rss-f7ec74a31984------2</link>
            <guid isPermaLink="false">https://medium.com/p/78385438aba3</guid>
            <category><![CDATA[jdbc-http-session]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[spring-session]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[json]]></category>
            <dc:creator><![CDATA[Raphael Militani]]></dc:creator>
            <pubDate>Wed, 04 Sep 2019 20:42:22 GMT</pubDate>
            <atom:updated>2019-10-25T10:19:14.931Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/578/1*piaHvxL8gF66zTl_OFoqnA.png" /></figure><p>In a certain job that I have been worked there was a requirement on application data persistence that the session should be persisted by Spring Session and the attributes of that session should be visible in a query of the database.</p><p>At first I thought, “Ok, it is very easy”, but as I started develop I started to have some problems. The Spring Session framework persist the attributes of the session in a BLOB type, and I did not see any ease way to change it.</p><p>I could create a method to read the BLOB and return the JSON value, but it is not acceptable because the requirement was to persist in the String type.</p><p>The way I found to solve the problem was change the default behavior of the Spring Session, creating a Spring Bean to configure a Spring Session and creating a class that extend the <a href="https://docs.spring.io/spring-session/docs/current/api/org/springframework/session/jdbc/JdbcOperationsSessionRepository.html"><strong>JdbcOperationsSessionRepository </strong></a>class which is responsible for data persistence.</p><p>First, I created a Bean class named <strong>HttpSessionConfig </strong>with @EnableJdbcHttpSession defined and a Bean to override the JdbcOperationSessionRepository configuration.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3e0689358afb9da8d8395b8f8252a675/href">https://medium.com/media/3e0689358afb9da8d8395b8f8252a675/href</a></iframe><p>After, I created a class named <strong>JDBCOperationSessionConfig </strong>that extend the main class of Spring Session: <strong>JdbcOperationsSessionRepository.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9eec3c68c4396b6395ae4c794938c453/href">https://medium.com/media/9eec3c68c4396b6395ae4c794938c453/href</a></iframe><p>In the constructor of the class JDBCOperationSessionConfig I set the lob handler as <strong>JDBCLobHandlerConfig </strong>class which extend the <strong>DefaultLobHandler </strong>class from the Spring Session.</p><p>In this class I override two methods:<br><strong>getLobCreator: </strong>responsible to create a Lob Creator and change the behavior of persistence method from BLOB to String.</p><p><strong>getBlobAsBytes: </strong>responsible to read the JSON string data from the database and parse it to byte array so that the reading behavior of the framework does not change.</p><p>After that I needed to create one more inner class named: <strong>JDBCLobCreatorConfig </strong>that extend <strong>LobCreator </strong>class.</p><p>With this code I was able to change the default behavior of the Spring Session, storing the attributes in JSON instead of BLOB.</p><p>You can view the source code in github: <a href="https://github.com/ramilitani/custom-session">https://github.com/ramilitani/custom-session</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=78385438aba3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>