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.

3
  • stackoverflow.com/questions/2327423/…. I have tried this but this not working. Commented Nov 19, 2019 at 17:16
  • Did you try 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. Commented Nov 20, 2019 at 7: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 Commented Nov 20, 2019 at 13:21

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.