<?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[ifelsecoder - Medium]]></title>
        <description><![CDATA[Articles based on real software development experience with all its pain and magnificent - Medium]]></description>
        <link>https://medium.com/ifelsecoder?source=rss----9ecf0718bfde---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>ifelsecoder - Medium</title>
            <link>https://medium.com/ifelsecoder?source=rss----9ecf0718bfde---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 05:58:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/ifelsecoder" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Spring Boot + Spring JPA + multiple data sources]]></title>
            <link>https://medium.com/ifelsecoder/spring-boot-spring-jpa-multiple-data-sources-3ac97de11b04?source=rss----9ecf0718bfde---4</link>
            <guid isPermaLink="false">https://medium.com/p/3ac97de11b04</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[spring-jpa]]></category>
            <category><![CDATA[multiple-database]]></category>
            <dc:creator><![CDATA[Oleksii Kondratiuk]]></dc:creator>
            <pubDate>Fri, 31 May 2019 16:05:38 GMT</pubDate>
            <atom:updated>2019-05-31T16:05:38.754Z</atom:updated>
            <content:encoded><![CDATA[<p>Suppose you faced with the challenge of having two data sources in your Spring Boot application. <a href="https://docs.spring.io/spring-boot/docs/current/reference/html/howto-data-access.html">Official documentation</a> tells you how to configure them. But how to use them for your JPA layer is not that clear. Here is my quick guide about it.</p><h3>Preface</h3><p>You can imagine our two databases as two parking lots — one for cars and one for trucks. Trucks don`t fit in on cars parking lot. Cars can fit in into trucks parking lot, but from an economic perspective, it does not make sense to reserve truck parking space for a car. I`ll use this case in my example project.</p><p>In real-world scenarios, it can be that we want one data source responsible for only writes cause it is master DB and the other one is just replica for reading operations only. Or it can be that second DB serves as some reports cause we generate them on a nightly basis. Of course, I`ll agree that in the microservice world you can have separate application two work with the second database. But sometimes it is not an option or not needed.</p><p>So lets` have a look at how the database layer can be quickly configured and then used.</p><h3>Configuration</h3><p>Lets` start with the configuration:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5cdea468075dbb404bea07b471024383/href">https://medium.com/media/5cdea468075dbb404bea07b471024383/href</a></iframe><p>Easy to encounter that we have <strong>app.cars.datasource</strong> and <strong>app.trucks.datasource</strong> reflecting two databases that we`re going to use.</p><h3>Application configuration for data sources</h3><p>Now lets` proceed with actual data sources in application. As you can see they use a different set of properties which we configured before.</p><p>One for cars:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0d49109ec1fd99d54b825093a113314f/href">https://medium.com/media/0d49109ec1fd99d54b825093a113314f/href</a></iframe><p>And one for trucks:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c044e020ad857f7005164fdbecb123e8/href">https://medium.com/media/c044e020ad857f7005164fdbecb123e8/href</a></iframe><h3>JPA repository</h3><p>Here are entities and JPA repositories of the project.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/12aea8f7a58d2b58e1c44263b3640451/href">https://medium.com/media/12aea8f7a58d2b58e1c44263b3640451/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/51359fbefe3539beeb189133187f65b3/href">https://medium.com/media/51359fbefe3539beeb189133187f65b3/href</a></iframe><p>JPA repositories:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c333626d17aaed14006ab092fbeb2d89/href">https://medium.com/media/c333626d17aaed14006ab092fbeb2d89/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/96a70eb0eeb6a514f859d06c747dba8b/href">https://medium.com/media/96a70eb0eeb6a514f859d06c747dba8b/href</a></iframe><h3>Entity managers configuration</h3><p>Now, to be able to use different data sources for different repositories we need to define entity manager configuration for cars and trucks. I made each in different configuration classes.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/87979e27dc4fe47601e9acd22514c356/href">https://medium.com/media/87979e27dc4fe47601e9acd22514c356/href</a></iframe><p>Also, notice EnableJpaRepositorie annotation which is important to enabling JPA repositories and EnableTransactionManagemen annotation to enable Spring transaction management.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/20236d169894d0b8c7e5bb6f9f01635d/href">https://medium.com/media/20236d169894d0b8c7e5bb6f9f01635d/href</a></iframe><p>EnableJpaRepository has basePackages property which specifies which package to scan for repository classes. Without it, repositories won`t be found. In our case repositories are located in different packages for the usage simplicity. You can come with any naming, but important to be able to quickly recognize which repository uses which database.</p><h3>Hibernate naming strategy</h3><p>Common SQL convention to use “_” delimiter in field names. For example, plate_name. In this case, the expectation will be that Car.plateNumber and Truck.plateNumber properties will mapped to plate_number column of respectful tables. It would automatically happen if the data source and entity manager was configured Spring JPA directly. Not the case anymore since we created these beans by ourselves instead. Hence you`ll get an exception:</p><blockquote>org.postgresql.util.PSQLException: ERROR: column truck0_.platenumber does not exist</blockquote><p>And it is totally true because the column is named plate_number, but property called platenumber. This means Hibernate tries to map the name of the property to name of the column as is. To fix this we need to set an appropriate naming strategy to our entity manager. You can check entity manager factory configuration again and encounter this line:</p><blockquote>.properties(jpaProperties)</blockquote><p>It corresponds to bean with name commonJpaProperties:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/385785d450facfc79d7c836adbe41dcc/href">https://medium.com/media/385785d450facfc79d7c836adbe41dcc/href</a></iframe><p>And add hibernate strategy properties to configuration like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1e5a425d556293f216fe1ea239dbea68/href">https://medium.com/media/1e5a425d556293f216fe1ea239dbea68/href</a></iframe><h3>Conclusion</h3><p>By implementing this all I realize how many things Spring JPA preconfigure for you which allows you quickly start business logic implementation. I appreciate the fact that still, you have the flexibility to add more data sources and use JPA repositories which is very handy.</p><p>You can check the <a href="https://github.com/oleksii-kondratiuk/spring-boot-with-multiple-datasources">whole project on Github</a>. Thanks, hope you find it useful!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3ac97de11b04" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ifelsecoder/spring-boot-spring-jpa-multiple-data-sources-3ac97de11b04">Spring Boot + Spring JPA + multiple data sources</a> was originally published in <a href="https://medium.com/ifelsecoder">ifelsecoder</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Spring Boot Maven plugin overrides IntelliJ IDEA debug parameters]]></title>
            <link>https://medium.com/ifelsecoder/spring-boot-maven-plugin-overrides-intellij-idea-debug-parameters-f85ff80090ca?source=rss----9ecf0718bfde---4</link>
            <guid isPermaLink="false">https://medium.com/p/f85ff80090ca</guid>
            <category><![CDATA[debug]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[spring-boot-2]]></category>
            <dc:creator><![CDATA[Oleksii Kondratiuk]]></dc:creator>
            <pubDate>Fri, 26 Apr 2019 19:15:52 GMT</pubDate>
            <atom:updated>2019-04-26T19:15:51.869Z</atom:updated>
            <content:encoded><![CDATA[<p>Suppose you joined some project, started to develop and you need to debug some piece of code.</p><p>I guess a very familiar case for most developers. And thanks to IntelliJ IDEA it is very easy to configure. That would be it for this article, but I had a very particular case which led me spending some time figuring out why my code does not stop on breakpoints.</p><p>Very common project setup — Java 8, Spring Boot 2.0.4 and pretty much it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/968/1*wV5-8btKvMa3fjSTlQQx5g.png" /></figure><p>Maven plugin allows you to start an application and IDE allows you to do it in debug mode by adding specific parameters to the startup command underneath. Problem is that application started, debug attached, but no stops on breakpoints.</p><p>I managed to configure remote debug by adding this to JVM options:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b5ac8e847aa3c6d4050231ba49887810/href">https://medium.com/media/b5ac8e847aa3c6d4050231ba49887810/href</a></iframe><p>It was not really convenient to remember that I need to run this particular microservice in debug mode differently. So I spent some time and actually found out why running via plugin was not working. Here is its configuration:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5d8559d9abb5de2414b05a5a336b207d/href">https://medium.com/media/5d8559d9abb5de2414b05a5a336b207d/href</a></iframe><p>As you can see there is JVM argument specified in the configuration. This is exactly what caused the strange behavior of the plugin. Debug via spring:run in IntelliJ IDEA starts working fine as soon as you remove this configuration. This all because it overrides what IDE puts into the command line as debug parameters.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f85ff80090ca" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ifelsecoder/spring-boot-maven-plugin-overrides-intellij-idea-debug-parameters-f85ff80090ca">Spring Boot Maven plugin overrides IntelliJ IDEA debug parameters</a> was originally published in <a href="https://medium.com/ifelsecoder">ifelsecoder</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>