I have an application that is using Hibernate and PostgreSQL, I compile it with Maven to a WAR and deploy it to a Tomcat 8.0, and sometimes I have the problem of this error :
"User lacks priviledge or object not found: TABLE_NAME".
Well obviously the answers found to this problem are always "Check the priviledges to that user, and check if the table/database exists".
This absolutely is not the problem because this happens sporadically, i.e. My application is working fine, and when I deploy a new version of it, sometimes after the deploy it throws out this error.
I always deploy my application with Jenkins, and the deploys to Tomcat are successful, the application is working, but if I invoke an action that consumes a database service, it goes haywire with this error. This clears up after 2 to 3 clean deploys on it (i.e. I stop Tomcat, clean the directory, start it and run deploy with Jenkins again with the same version of code).
Still it is very odd that after a clean deploy it does not solve the problem. Even after restarting the whole server (not Tomcat, the Windows Server), it still happens.
The closest explanation I read about possible causes to this, is that sometimes it can create a ghost connection to the database and when it tries to query something it can't because it is not really connected.
The database is on the same server as the Tomcat, so the application points to localhost to connect to the database. I don't think this is related because it also happens in a Quality Rnvironment where the database is in a different server.
My configuration file regarding database is this:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<alias name="appDataSource" alias="jpaDataSource" />
<alias name="jpaTransactionManager" alias="appTransactionManager" />
<bean id="appDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.postgresql.Driver" />
<property name="url" value="${postgre.url}" />
<!-- jdbc:postgresql://127.0.0.1:5432/DEV_DATABASE -->
<property name="username" value="${postgre.username}" />
<property name="password" value="${postgre.password}" />
</bean>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="jpaDataSource" />
<property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
<property name="packagesToScan" value="${persistence.jpa.packagesToScan}" />
<property name="jpaProperties">
<props>
<prop key="hibernate.temp.use_jdbc_metadata_defaults">false</prop>
<prop key="hibernate.jdbc.use_get_generated_keys">true</prop>
</props>
</property>
<property name="sharedCacheMode" value="ENABLE_SELECTIVE" />
<property name="validationMode" value="NONE" />
</bean>
</beans>
Anyone got ideias of what this could be?
It's been a few months and I've been able to find out what was happening.
Apparently I had a configuration of an embedded-database and sometimes (though rarely) the application would connect to this embedded-database and not the one that I had configured to connect to Postgres Database.
The tag was:
<jdbc:embedded-database id="appDataSource" />
Because this was an empty mockup database, it would fire up the error of "User lacks priviledge or object not found" because the table did not exist in this empty database.
After removing this, the problem was solved, it now always connects to the correct database.