• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

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

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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){
  //code....
}
I will be glad to get any advice!
 
Saloon Keeper
Posts: 26540
187
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 2265
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
http://zetcode.com/springboot/crudrepository/
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic