How to read .sql file with Java

0

I have a complex query in MySQL with sub-select and joins .

I would like to read this script through a .sql file using the JPA / Hibernate language (JPQL or HQL), for example getSession().createQuery(arquivo.sql); .

Or another way that will allow me to read the file be having to be fetched the script in the repository. Is this possible?

    
asked by anonymous 09.08.2018 / 21:39

1 answer

0
String sqlString = path_to_file;
String sql = IOUtils.toString(new FileInputStream(sqlString), "UTF-8");
getSession().createSQLQuery(sql);

I took advantage of Hibernate's tranformers to handle the information and transform into a Dto.

    
10.08.2018 / 14:56