I developed a web application on a test server, with an Oracle10g test database, using Hibernate 3.6.0 for ORM. Everything works fine on the test server.
When I moved this web application to the production server and the production Oracle10g database, I encountered a strange issue: the server times out when I try to run an update query in Hibernate (I receive an Internal Server Error).
These are the last lines logged by Tomcat:
2011-05-03 15:45:09,083 DEBUG (org.hibernate.pretty.Printer:113) - fsmodule.model.Organization{organizationid=65, ogroup=fsmodule.model.Ogroup#5, nature=fsmodule.model.Nature#2, name=Norway, factsheets=<uninitialized>}
2011-05-03 15:45:09,083 DEBUG (org.hibernate.pretty.Printer:110) - more......
2011-05-03 15:45:09,091 DEBUG (org.hibernate.jdbc.AbstractBatcher:410) - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2011-05-03 15:45:09,092 DEBUG (org.hibernate.SQL:111) - update RESPONSE set FACTSHEET_FACTSHEETID=?, QUESTION_QUESTIONID=?, TEXT=? where RESPONSEID=?
2011-05-03 15:45:09,099 DEBUG (org.hibernate.jdbc.AbstractBatcher:66) - Executing batch size: 1
... and that's all! No error outputed, nothing else. The select queries work very well, but I have the same issue with the insert queries.
Moreover, my users told me that the application worked fine at first, and then it stopped working correctly (I did not change the web application whatsoever in the meantime).
Also note that if I connect directly to the database with the same credentials than the ones used by the hibernate.cfg.xml file, I can flawlessly update the rows.
What could be going wrong?
Thank you all for your always-precious help.
Have you configured c3p0 connection pool? http://community.jboss.org/wiki/HowToConfigureTheC3P0ConnectionPool
Related
I have a web application where I have been used
org.springframework-version: 4.1.4.RELEASE
spring.security.version: 3.2.5.RELEASE
org.hibernate-version: 3.5.1-Final.
java version 1.6
org.postgresql: 7.4.1-jdbc3
I'm trying to upgrade the spring, and the hibernate version where I successfully updated the following in my pom file
org.springframework-version: 5.3.6
spring.security.version: 5.4.6
org.hibernate-version: 5.4.31.Final
java version 11.0.2
org.postgresql: 42.0.0
And I have also updated the related XML file where I mentioned the spring security beans. I'm using Postgres DB. Also, everything is working fine in my system, and when I commit these changes to the QA environment, the login is not working.
I'm checked for the log when logging into the application, and it shows some errors. Here is the log
[http-nio-8080-exec-7] WARN org.hibernate.engine.jdbc.spi.SqlExceptionHelper - SQL Error: 0, SQLState: 0A000
[http-nio-8080-exec-7] ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper - This method is not yet implemented.
20210616-02:51:01.539 sitepm-service [http-nio-8080-exec-9] ERROR o.h.e.jdbc.spi.SqlExceptionHelper.logExceptions - This method is not yet implemented.
20210616-02:51:01.539 sitepm-admin [http-nio-8080-exec-9] ERROR o.h.e.jdbc.spi.SqlExceptionHelper.logExceptions - This method is not yet implemented.
20210616-02:51:01.542 sitepm-service [http-nio-8080-exec-9] ERROR c.s.a.u.controller.LoginController.setExceptionPage - org.hibernate.exception.GenericJDBCException: could not prepare statement
20210616-02:51:01.542 sitepm-admin [http-nio-8080-exec-9] ERROR c.s.a.u.controller.LoginController.setExceptionPage - org.hibernate.exception.GenericJDBCException: could not prepare statement
Checked the Postgres version on the ubuntu server
ubuntu#ip-10-0-0-14:~$ psql --version
psql (PostgreSQL) 12.2 (Ubuntu 12.2-2.pgdg18.04+1)
Can anyone help me to solve this issue? Thanks
Also, how to check the PostgreSQL JDBC driver version in the ubuntu server
That org.postgresql dependency that you upgraded to 42.0.0? That is the Postgres JDBC driver. It talks directly to the postgres server running at whatever IP you put in your JDBC URL connection string.
You can check the postgres version (so not the JDBC driver, postgres - the actual database engine) on ubuntu using the command pg_lsclusters - you may have to sudo it, or run it as user postgresql. The first column (with header Ver) is listing the DB storage version, which matches with major versions of postgres.
You can also run psql --version.
20210616-02:51:01.542 sitepm-service [http-nio-8080-exec-9] ERROR c.s.a.u.controller.LoginController.setExceptionPage - org.hibernate.exception.GenericJDBCException: could not prepare statement
There is a ton of information missing. There should be a stack trace, there should be an SQLState value (the same value you get from invoking .getSQLState() on an SQLException), and probably a cause with more information as well.
If this is all you have, you are probably engaging in this extremely bad practice which is regrettably somewhat common amongst newbies, SO answers, and tutorials:
try {
stuff();
} catch (SomeException e) {
log(e.getMessage());
}
Search your codebase for this anti-pattern and delete it all. This is no good. The correct approach to deal with exceptions you can't handle (and most, as in 90%+, of all exceptions cannot be handled) is to throw it onwards. If you can't because of API restrictions, wrap it. Update your IDE templates and the like, because the fire and forget I do not want to think about it solution is this:
try {
stuff();
} catch (SomeException e) {
throw new RuntimeException("Uncaught", e);
}
This will ensure code stops running (this is good - by definition you do not fully understand the exotic conditions that caused this exception to occur, so by definition then you have no idea what you're doing from this point onwards. Therefore, continuing execution is thus running code that wasn't written from the situation at hand - obviously a silly plan) - and ensures all relevant info is retained and should end up in your logs.
Alternatively, find the place where this occurs and log e.getSQLState() (which should get logged anyway if you follow my advice above). You can search for that code + 'psql jdbc' and get a much more detailed page on exactly what's going on.
--EDIT--
psql error states are described on this psql documentation page.
State 0A means: "Feature not supported".
Evidently, hibernate is trying to send some SQL that psql recognizes but doesn't support. You can configure hibernate to print the query, and the SQLException may contain that info as well.
currently I'm struggling with Neo4j/GrapheneDB (Dev free plan) on Heroku platform.
Launching my app locally via "heroku local" works fine, it connects (Neo4j Java Driver 4) to a Neo4j 3.5.18 (running from Docker image "neo4j:3.5").
My app is built using Micronaut framework, using its Neo4j support. Launching my app on Heroku platform succeeds, I'm using Gradle Heroku plugin for this task.
But accessing the database with business operations (and health checks) fails with exception like this:
INFO Driver - Direct driver instance 1523082263 created for server address hobby-[...]ldel.dbs.graphenedb.com:24787
WARN RetryLogic - Transaction failed and will be retried in 1032ms
org.neo4j.driver.exceptions.ServiceUnavailableException: Connection to the database terminated. Please ensure that your database is listening on the correct host and port and that you have compatible encryption settings both on Neo4j server and driver. Note that the default encryption setting has changed in Neo4j 4.0.
at org.neo4j.driver.internal.util.Futures.blockingGet(Futures.java:143)
at org.neo4j.driver.internal.InternalSession.beginTransaction(InternalSession.java:163)
at org.neo4j.driver.internal.InternalSession.lambda$transaction$4(InternalSession.java:147)
at org.neo4j.driver.internal.retry.ExponentialBackoffRetryLogic.retry(ExponentialBackoffRetryLogic.java:101)
at org.neo4j.driver.internal.InternalSession.transaction(InternalSession.java:146)
at org.neo4j.driver.internal.InternalSession.readTransaction(InternalSession.java:112)
at org.neo4j.driver.internal.InternalSession.readTransaction(InternalSession.java:106)
at PersonController.logInfoOf(PersonController.java:57)
at PersonController.<init>(PersonController.java:50)
at $PersonControllerDefinition.build(Unknown Source)
at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1814)
[...]
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.base/java.lang.Thread.run(Thread.java:832)
Suppressed: org.neo4j.driver.internal.util.ErrorUtil$InternalExceptionCause: null
at org.neo4j.driver.internal.util.ErrorUtil.newConnectionTerminatedError(ErrorUtil.java:52)
at org.neo4j.driver.internal.async.connection.HandshakeHandler.channelInactive(HandshakeHandler.java:81)
[...]
at org.neo4j.driver.internal.shaded.io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at org.neo4j.driver.internal.shaded.io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
... 1 common frames omitted
I'm sure to get login credentials from OS environment variables GRAPHENEDB_BOLT_URL, GRAPHENEDB_BOLT_USER, and GRAPHENEDB_BOLT_PASSWORD injected to the app correctly; I've verified it with some debug log statements:
State changed from starting to up
INFO io.micronaut.runtime.Micronaut - Startup completed in 2360ms. Server Running: http://localhost:7382
INFO Application - Neo4j Bolt URIs: [bolt://hobby-[...]ldel.dbs.graphenedb.com:24787]
INFO Application - Neo4j Bolt encrypted? false
INFO Application - Neo4j Bolt trust strategy: TRUST_SYSTEM_CA_SIGNED_CERTIFICATES
INFO Application - Changed trust strategy to: TRUST_ALL_CERTIFICATES
INFO Application - Env.: GRAPHENEDB_BOLT_URL='bolt://hobby-[...]ldel.dbs.graphenedb.com:24787'
INFO Application - Env.: GRAPHENEDB_BOLT_USER='app1[...]hdai'
INFO Application - Env.: GRAPHENEDB_BOLT_PASSWORD of length 31
I've also tried restarting GrapheneDB instance via Heroku plugin website, but with same negative results.
What's going wrong here? Are there any ways to further nail down the root cause?
Thanks
Christian
I had a closer look at this and it seems that you need the driver encryption turned on for the Graphene db instances. This can be configured in application.yml as below:
neo4j:
encryption: true
For reference, here is a sample project https://github.com/aldrinm/micronaut-neo4j-heroku
I just installed MySql Community Server, and I have a MySql Connection called mysqlserver. I created a schema called library, with some tables. Everything seems fine with the database, but when I try to generate bean classes with hibernate reverse engineering from Eclipse, I am getting this error:
org.hibernate.exception.SQLGrammarException: Getting database metadata
Getting database metadata
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database 'mysqlserver'
Unknown database 'mysqlserver'
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database 'mysqlserver'
Unknown database 'mysqlserver'
The interesting thing is that my tables are fetching, so I can see them from Eclipse, but the error is still here while trying to generate classes.
My guess was that the problem is with my url, but how are tables fetched then:
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password">mypassword</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/library</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
I do not get it how can mysqlserver be unknown database, when I specified that my database is library. I lost hours while trying to google it, and still nothing. Can anyone help me with this please?
Now, I am experiencing a new problem - I cannot start the server any more. I stopped it yesterday, and tried to start it now, it just won't start any more. The server log says:
Could not open error log file: [Errno 2] No such file or directory: 'SAMS-PC.err'
2014-02-06 13:10:32 - Status check of service 'MySQL56' returned stopped
2014-02-06 13:10:32 - Starting server...
2014-02-06 13:10:34 - Status check of service 'MySQL56' returned stopped
2014-02-06 13:10:34 - Server start done.
2014-02-06 13:10:34 - Status check of service 'MySQL56' returned stopped
Your jdbc string should be
hibernate.connection.url = jdbc:mysql://localhost:3306/mysqlserver
hibernate.default_schema = library
you schema is library, you database name mysqlserver.
I resolved the last issue, with starting the server from console. I don't know why MySql workbench didn't start it, but I will be satisfied with this solution for now. Later the server stopped working again, and so on... So, I concluded that I do not like MySql very much.
I solved the original problem, too. The problem was something unrelated to hibernate configuration - I forgot to create a .reveng.xml file. Embarrassing...
Anyway, thank you for willingness to help.
I am using a brand new developing pc and need to test a personal application that runs on a local GlassFish server 3.1.2 and should connect with a local SQL database called 'funkOneDB' (my IDE is NetBeans 7.2.1). But I can't get the GlassFish server to connect with the database, and the problem seems to be related to the (place of the) SQL driver in the GlassFish Server's directories (more problem specifics in a few lines).
I am fairly certain I correctly set up the related JDBC Resource and Connection Pool on the GlassFish Server (as I mimic a set-up already existing and working properly on another developing pc).
The Resource specifics are:
jndi name: jdbc/FunkResource
pool name: FunkPool
The (most important) Pool specifics are:
pool name: FunkPool
resource type: javax.sql.Datasource
datasource classname: com.mysql.jdbc.jdbc2.optional.MysqlDataSource
additional properties correspond to the specifics in the XML GlassFish-resources of the application (username, password, url, etc.; no problems there)
I first placed the necessary SQL driver in the GlassFish Server's directories, i.e. the file mysql-connector-java-5.1.18-bin.jar at ..\GlassFish3\GlassFish\domains\domain1\lib\ext.
Yet, when I perform a ping test from the JDBC Pool 'FunkPool' at the GlassFish server, I get the following error:
Ping Connection Pool failed for FunkPool. WEB9031: WebappClassLoader unable to load resource [com.mysql.jdbc.SQLError], because it has not yet been started, or was already stopped Please check the server.log for more details.
In the server.log I only find the following extra logging exception and failure info:
(i) Exception while creating an unpooled [test] connection for pool [ FunkPool ], WEB9031: WebappClassLoader unable to load resource [com.mysql.jdbc.SQLError], because it has not yet been started, or was already stopped
(ii) RestResponse.getResponse() gives FAILURE. endpoint = 'http://localhost:4848/management/domain/resources/ping-connection-pool.json'; attrs = '{id=FunkPool}'
Note however, that when I ping the database funkOneDB from my IDE NetBeans via jdbc:mysql://localhost:33066/funkOneDB, it's succesful. As already mentioned, the credentials and other data I use for this IDE-based ping are the same data I use in the JDBC Connection Pool.
I searched for the problem also on stackoverflow for some. And I did find some people talking about it, like
Glassfisch MySQL ping ERROR (no answer by anybody), or
Struggling to create MySQL Connection Pool on Glassfish (tried that solution, i.e. putting the SQL driver one level up in ..\GlassFish3\GlassFish\domains\domain1\lib\, but this creates other errors, even after restarting the Glassfish server), or
GlassFish not loading connector
(even tried this solution, no succes).
Can somebody help me solve this problem? Many thanks in advance!
With kind regards,
Heinz
Place the mysql driver in the lib folder of your project. Then do a clean-and-build. It's also helpful to have netbeans communicate directly with your database. This will allow you to view the database structure and the contents of your database right from your IDE. For help integrating MySQL with netbeans, look here: netbeans.org/kb/docs/ide/mysql.html
My friend, i had this same exception:
RestResponse.getResponse() gives FAILURE. endpoint = 'http://localhost:4848/management/domain/resources/ping-connection-pool.json'; attrs = '{id=FunkPool}'
The cause of my error was that, i put wrong credentials. Check your credentials in your client DB App (SQL Developer, for example).
I had the same problem with SQL server and Netbeans. To resolve it, i put the sqljdbc.jar in the java direcory "Java\jdk1.8.0_121\lib directory" and it works :)
I've just spebnt 10 hours on this bug.
I am writing a struts2 app and using hibernate for persistence. I deploy may app on heroku and everything works ok, but when ever I run it locally I get:
org.postgresql.util.PSQLException: FATAL:no pg_hba.conf entry for host "xx.xx.xxx.xxx", user "someuser", database "somedatabase", SSL off
I know the problem is I need to connect to the database over ssl but how can I set this up locally?
Add this to the end of your JDBC connection URL:
?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory
The key here is "SSL off".
You must use SSL to connect to Heroku. How to enable it depends on the client you are using, which I'm guessing is PgJDBC since you're using Java and Hibernate.
The SSL section of the manual for PgJDBC covers what you need.