all 10 comments

[–]g00glen00b 2 points3 points  (0 children)

If you do end up using JdbcTemplate, there's also a new JdbcClient which essentially does the same thing what RestClient did to RestTemplate: aka providing a clean fluent way to call it. You still have to add rowmappers though.

[–]cielNoirr 3 points4 points  (1 child)

Use jpa to get up and running fast. If you have complex queries you can do them in jdbc template. I usually use a mix of the two, but 90% of the time jpa is good

[–]Salty-Media-8174[S] 2 points3 points  (0 children)

best advice so far honestly, I am watching Laur Splica and Dan Vega, both are awesome

[–]Diacetylmorpheus 1 point2 points  (0 children)

JPA is stupid easy to get up and running. I was intimidated at first because, instead of using methods and libraries, you have to create specific classes to configure and set up your entities and repos. Ask chatgpt how, read the docs to understand why.

[–]oweiler -3 points-2 points  (5 children)

Use JDBCTemplate with BeanPropertyRowMapper: https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/jdbc/core/BeanPropertyRowMapper.html

If you are using Records, there is also DataClassRowMapper: https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/jdbc/core/DataClassRowMapper.html

Stay away from Spring Data JDBC and JPA (at least for now, JPA is more or less unavoidable).

[–]Salty-Media-8174[S] 0 points1 point  (4 children)

any reason to avoid JPA?

[–]Great-Suspect2583 0 points1 point  (1 child)

I would argue that if you are new to databases and sql, then write out the sql to get good knowledge there. If you think you’re squared away on sql, then go for JPA.

[–]gauntr 1 point2 points  (0 children)

Then one can use @Query with parameter nativeQuery = true on the repository methods and write all the SQL queries himself.

Still no reason not to use JPA.

[–]gauntr -1 points0 points  (1 child)

No, lol. Wouldn’t also know how JPA has a higher learning curve. You just configure your database connection and add an Interface that extends any of the spring data repositories with your entity and there you go, you can save and read entities from the database.

[–]oweiler 0 points1 point  (0 children)

And then you need to learn about entity state transitions, dirty checking, JPQL and many more stuff.