2

I am trying to validate database schema before running any queries using jdbc template. So is there any way to identify schema changes before making any queries in spring programmatically?? Currently I am using spring boot 2 and hibernate 5.

  • https://stackoverflow.com/questions/2327423/how-to-validate-database-schema-programmatically-in-hibernate-with-annotations. I have tried this but this not working. – prakash pichaimuthu Nov 19 '19 at 17:16
  • Did you try https://stackoverflow.com/a/8927578/3519504 from the above solution? That could be a programmatic way to do what you want, or you can use `hibernate.hbm2ddl.auto=validate` in the configuration file. – Sandeep Kumar Nov 20 '19 at 07:08
  • I Have tried that too. But Since I am using the latest version the annotation session factory has been deprecated. In Spring I am using jdbc template to make a query – prakash pichaimuthu Nov 20 '19 at 13:21

1 Answers1

2

Add this to the configuration file.

hibernate.hbm2ddl.auto=validate

If the value is validated then hibernate only validates the table structure- whether the table and columns have existed or not. If the table doesn’t exist then hibernate throws an exception.

Validate is the default value for hbm2ddl.auto.

Atul Jain
  • 1,035
  • 2
  • 16
  • 24
  • This will only work if you start the application first time. I need a way to validate the schema before making query to database. Like a function will validate the schema using java. – prakash pichaimuthu Nov 20 '19 at 13:19