Reputation: 405
I want to flush my data, for this I have the following method
@RequestMapping(value = "/add", method = RequestMethod.POST)
@Transactional
public String musicSubmit(@ModelAttribute Music music, Model model) {
musicRepository.saveAndFlush(music);
model.addAttribute("music", music);
return "result";
}
My model
public interface MusicRepository extends JpaRepository<Music, Integer> {
}
My main
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
My data are visible but if I shutdown the application and run again, they disapears even if I set my applications.properties like this
spring.jpa.hibernate.ddl-auto = update
How can I keep my data, even if shutdown the application or restart my computer ?
Upvotes: 2
Views: 6018
Reputation:
Use these in application.properties
:
spring.datasource.url = jdbc:h2:file:~/some_path/YourVeryDbFile
spring.datasource.username = sa
spring.datasource.password =
spring.datasource.driverClassName = org.h2.Driver
spring.jpa.database = H2
spring.jpa.show-sql = true
Notice this uses H2; if you want something else (MYSQL) you should specify it otherwise (and change the values accordingly).
Have a look here.
Upvotes: 1