• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

How can I create postgres entries with the CrudRepository from spring framework?

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am attempting to create a entry in my database and have figured out how to update a existing row through a POST request. I am having trouble figuring out how to create a entry every time my function is called. I am using the `.save()` function from CrudRepository and that does seem to do what it says and saved to an existing entry but not create. Can someone help me out with this? maybe I am just missing something small.
 
Bartender
Posts: 2266
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, using save() in CrudRepository is to save the entity. But you need to make sure your Spring Boot application is connecting to the DB.
Here is a reference:
https://spring.io/guides/gs/accessing-data-mysql/
 
Rancher
Posts: 100
4
VI Editor Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Method save() in CrudRepository does not necessarily create new table record, if you use same entity id/primary key with different data, it will execute as UPDATE of existing record, not INSERT of new one.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic