The hibernate.cfg.xml file looks like this:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database Connection Settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/MYDATABASE</property>
<property name="connection.username">MYUSER</property>
<property name="connection.password">MYPASSWORD</property>
<!-- Connection Pool Size (built-in) -->
<property name="connection.pool.size">1</property>
<!-- SQL Dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- Disable the second-level cache -->
<!--<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>-->
<!-- Echo all executed SQL to stdout -->
<property name="hibernate.show_sql">true</property>
<!-- Drop the existing tables and create new one -->
<property name="hbm2ddl.auto">create</property>
<!-- Mention here all the model classes along with their package name -->
<!--<mapping class="no.numbershopper.numbershopper.service_layer.admin_web"/>-->
</session-factory>
</hibernate-configuration>
I needed this in order to run SQL queries using normal API calls (I wouldn’t mind if there was a way to do it without an xml file):
org.hibernate.cfg.Configuration cfg = new org.hibernate.cfg.Configuration();
SessionFactory sessionFactory = cfg.configure().buildSessionFactory();
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
ArrayList postList = new ArrayList();
for (Post post : posts) {
String queryString = "SELECT post_resource.file_upload_id, post_resource.link, file_upload.content_type FROM post_resource INNER JOIN file_upload ON file_upload.id = post_resource.file_upload_id WHERE post_resource.post_id=" + post.getId();
SQLQuery query = session.createSQLQuery(queryString);
List<Object[]> rows = query.list();
Anyway, the problem is that it works when I run it in my development environment, but when I put it out on a remote horaku server, it does not. I get the following output from tomcat/spring:
2018-05-08T13:46:19.395002+00:00 app[web.1]: 2018-05-08 13:46:19.394 ERROR 4 --- [io-45958-exec-3] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]] with root cause
2018-05-08T13:46:19.395014+00:00 app[web.1]:
2018-05-08T13:46:19.395018+00:00 app[web.1]: java.net.ConnectException: Connection refused (Connection refused)
The login information in the config file is correct, it’s a copy from the application.properties file. So it seems like it’s not an authentication error, but related to something else.
I hope someone out there knows what the problem could be. Thanks.