This series is about all things related to using Spring Boot for web development.
The problem
I was facing this problem: I have a BlogPost entity and I want to be able to query the BlogPost table in my database for any blog post containing a certain title.
The solution
@Query(value = "SELECT * FROM blogPost WHERE blogPost.title LIKE %:title%",nativeQuery = true)
List<BlogPost> findBlogPostByTitle(@Param("title") String title);
The weird bug I encountered
I was using the the 'LIKE' operator but I kept running into a weird bug where it would only return the first value matched and not all the values. It turns out that it was due to improper syntax when passing the parameter to the SQL query. So if you are having a similar problem, check the syntax of your SQL.
Conclusion
Thank you for taking the time out of your day to read this blog post of mine. If you have any questions or concerns please comment below or reach out to me on Twitter.
Top comments (0)
Subscribe
For further actions, you may consider blocking this person and/or reporting abuse
History repeats itself. Everything old is new again and I’ve been around long enough to see ideas discarded, rediscovered and return triumphantly to overtake the fad. In recent years SQL has made a tremendous comeback from the dead. We love relational databases all over again. I think the Monolith will have its space odyssey moment again. Microservices and serverless are trends pushed by the cloud vendors, designed to sell us more cloud computing resources.
Microservices make very little sense financially for most use cases. Yes, they can ramp down. But when they scale up, they pay the costs in dividends. The increased observability costs alone line the pockets of the “big cloud” vendors.
Top comments (0)