• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Stephan van Hulst
  • Frits Walraven
  • Carey Brown
  • Jj Roberts

Creating save(T t)method in one-many relationship via JdbcTemplate in Spring Boot Rest

Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone! I am new to Spring Boot and Spring Boot Rest and try to understand how should I perform CRUD operations in Spring JDBC without JPA and Hibernate. For example I have two classes: Product and ProductCategory which means that many categories can belong to one product and vice versa. 1) In what way  I  need to keep reference on ProductCategory( long productCategoryId or ProductCategory product category) 2) What parameters I have to pass in method which saves products and categories?
I think they should be like this:
1) For product
public void save( Product product, Long productCategoryId){
    // code....
2)For category(ProductCategory product category){
I will be glad to get any advice!
Saloon Keeper
Posts: 22801
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch, Volodymyr!

I gave up on Spring JDBC a long time ago. I figure that if an application is complex enough to need Java, it's probably complex enough to justify JPA and Spring JPA is very functional and popular, especially with Hibernate JPA, but I've also used with Apache OpenJPA.

When using Spring JDBC, I'd probably have a separate DAO for Product and for ProductCategory and save/update each table using a save method in the 2 DAOs. Doing it any other way is just about the same as using JPA, but without the benefits of JPA.
Posts: 1979
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Volodymyr,
You may find this SpringBoot CrudRespository tutorial helpful.
With Spring data JPA, you don't need to write queries to save your Product.
We begin by testing your absorbancy by exposing you to this tiny ad:
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic