how to run CUSTOM DDL DML ... On Spring Boot at run time, Without Forcing Hibernate

2.3k views Asked by At

How to access database and run custom executable or query on it? after some search i found that i can use sessionFactory, but i have to force hibernate as data handler, well that make me worry if it have some bad effect or behavior in my complex part of application, depending on the way it links data together, or the way it fetches joined data and handles them... so i want to go with spring default... also if it doesn't preferred hibernate, it may mean that hibernate is slower. i want to access the online session (previously i used NHibernate on C#, and creating secondary session could be problematic), so i want to access exists session of database, beside when i use JpaRepository, and run the custom command on it. so i don't disturb other session, or locks :|

BTW i'm using HSQLDB for now...

1

There are 1 answers

6
Ulises On BEST ANSWER

Spring JDBC has a DataSource initializer feature. Spring Boot enables it by default and loads SQL from the standard locations schema.sql and data.sql (in the root of the classpath). In addition Spring Boot will load the schema-${platform}.sql and data-${platform}.sql files (if present), where platform is the value of spring.datasource.platform, e.g. you might choose to set it to the vendor name of the database (hsqldb, h2, oracle, mysql, postgresql etc.).The script locations can be changed by setting spring.datasource.schema and spring.datasource.data, and neither location will be processed if spring.datasource.initialize=false.

More here

If you put the hibernate jars in you classpath then Spring's autoconfiguration will take over and think that you wanna user Hibernate. So make sure you don't have those jars in your classpath.