Hello i am trying to use JBoss Hibernate Tools for Reverse engineering. I am using eclipse luna and latest hibernate jboss tools from eclipse market place. When i trying to configure the hibernate tools configuration, After configuration done, when i expand the tree and expand database node, it generate an following error:
<Reading Schema Error: Could not get list of suggested identity strategies from database. Probably a JDBC Driver Problem>
Stack Trace:
org.hibernate.exception.SQLGrammarException: Could not get list of suggested identity strategies from database. Probably a JDBC driver problem.
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92)
at org.hibernate.cfg.reveng.dialect.MySQLMetaDataDialect.getSuggestedPrimaryKeyStrategyName(MySQLMetaDataDialect.java:55)
at org.hibernate.cfg.reveng.JDBCReader.processPrimaryKey(JDBCReader.java:429)
at org.hibernate.cfg.reveng.JDBCReader.readDatabaseSchema(JDBCReader.java:86)
at org.hibernate.eclipse.console.workbench.LazyDatabaseSchemaWorkbenchAdapter$2.execute(LazyDatabaseSchemaWorkbenchAdapter.java:126)
at org.hibernate.console.execution.DefaultExecutionContext.execute(DefaultExecutionContext.java:63)
at org.hibernate.console.ConsoleConfiguration.execute(ConsoleConfiguration.java:107)
at org.hibernate.eclipse.console.workbench.LazyDatabaseSchemaWorkbenchAdapter.readDatabaseSchema(LazyDatabaseSchemaWorkbenchAdapter.java:115)
at org.hibernate.eclipse.console.workbench.LazyDatabaseSchemaWorkbenchAdapter.getChildren(LazyDatabaseSchemaWorkbenchAdapter.java:65)
at org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter.fetchDeferredChildren(BasicWorkbenchAdapter.java:106)
at org.eclipse.ui.progress.DeferredTreeContentManager$1.run(DeferredTreeContentManager.java:238)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-empirecl-test like 'oauth_access_token'' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:408)
at com.mysql.jdbc.Util.getInstance(Util.java:383)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1062)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4226)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4158)
My database connection with eclipse is build successfully beacause with the help of Database explore by eclipse make connection successfully and also display all tables. I am using Hibernate 4.3 and latest MySQL driver 5.1.31. Following are the screen shots of my configuration.
Following is my hibernate.cfg.xml file:
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password">password</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/nit-empirecl-test</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
</session-factory>
</hibernate-configuration>
I found the solution, The problem is with database name. I don't know, but hibernate jboss tool, not support ( - ) Hyphen in database name. When i change the name with underscore the configuration will run successfully.
You should set the hibernate default schema (for sql server)
<property name="hibernate.default_schema">dbo</property>
I have the same problem, but with MS SQL Server and without "-" in DB name.
You can try to set the "optional" property hibernate.default_schema.
Related
When attempting to do this in my code:
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/MazeJumperLeaderboardDB", "root", "password");
I always seem to get this error no matter what I try:
java.sql.SQLException: java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:988)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:974)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:919)
at com.mysql.jdbc.ConnectionImpl.buildCollationMapping(ConnectionImpl.java:1062)
at com.mysql.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:3556)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2513)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2283)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:822)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:404)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:317)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
... 61 more
I am using Java NetBeans IDE 8.2 and using MySQL Connector Java 8.0.18.
I have looked at other questions, notably this one:
ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long on connect to MySQL
But, doing this resulted in the same 'java.sql.SQLException: java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long' error.
Furthermore, I seem to be able to connect to my database driver just fine, but when attempting to connect to the MySQL server, it displays an error message with the same error yet again.
I'm really not sure what else to try at this point, so any help would be greatly appreciated!
I managed to (finally) solve my issue.
The problem was with the pre-installed JDBC driver on NetBeans. The pre-installed JDBC driver was of version 5.1.23, which is outdated and did not match up with my installed JDBC driver from the MySQL website.
So, what I did was:
I deleted the pre-installed driver in the 'Libraries' folder on NetBeans (under your project, the libraries folder), then right clicked on my project, selected 'Properties', then 'Libraries', then I clicked 'Add JAR/Folder', then browsed through my system files and searched for the latest version of MySQL Connector that I had downloaded (Connector/J 8.0.18), and then I added the .zip file. Then I went over to the services tab, and re-established the connection to the database and drivers using the SAME MySQL Connector version, and then it worked and stopped giving me this error.
Following error is arriving while I initailize after downloading the packages of opennms:
PLease tell me what I am doing wrong or any suggestions how to resolve this issue
OpenNMS Installer
Configures PostgreSQL tables, users, and other miscellaneous settings.
15:48:58.468 [Main] WARN org.opennms.install.Installer - Could not create file: /usr/share/opennms/etc/libraries.properties
- using SQL directory... /usr/share/opennms/etc
- using create.sql... /usr/share/opennms/etc/create.sql
15:48:58.496 [Main] INFO org.opennms.core.schema.Migrator - validating database version
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.opennms.bootstrap.Bootstrap$4.run(Bootstrap.java:525)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.opennms.core.schema.MigrationException: an error occurred getting the version from the database
at org.opennms.core.schema.Migrator.getDatabaseVersion(Migrator.java:183)
at org.opennms.core.schema.Migrator.validateDatabaseVersion(Migrator.java:211)
at org.opennms.install.Installer.install(Installer.java:245)
at org.opennms.install.Installer.main(Installer.java:991)
... 6 more
Caused by: org.postgresql.util.PSQLException: FATAL: password authentication failed for user "postgres"
at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:446)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:220)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:55)
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:219)
at org.postgresql.Driver.makeConnection(Driver.java:407)
at org.postgresql.Driver.connect(Driver.java:275)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:208)
at org.opennms.core.db.install.SimpleDataSource.getConnection(SimpleDataSource.java:113)
at org.opennms.core.schema.Migrator.getDatabaseVersion(Migrator.java:171)
... 9 more
Any suggestions?
It looks like you do not have permission to access the PostgreSQL database.
Did you edit pg_hba.conf?
I made a video on installing OpenNMS that you might find helpful. It covers the changes you need to make to PostgreSQL so that OpenNMS can access it.
This question already has answers here:
Can't connect to MySQL from Java: NullPointerException inside MySQL driver connection logic
(5 answers)
Closed 4 years ago.
I'm new in Databases just started to learn them. I have MySQL Server 8.0., Workbench 8.0, Java connector 5.1.31, Java 1.8 itself. Followed multiple guides for newbies how to start with.
So there is the case. I have database on localhost and successfully connect to it with workbench and via windows prompt. But after I execute code in java:
Driver sqlDriver = new FabricMySQLDriver();
DriverManager.registerDriver(sqlDriver);
Connection sqlConnection = DriverManager.getConnection("jdbc:mysql://localhost:3306/?user=root", "root", "root");
I get exception com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.
Why it could happen? I've tried to reinstall MySQL, Cleaned OS variables, looked everywhere and couldn't find solution. Would be glad to find it here.
UPD:
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:408)
at com.mysql.jdbc.Util.getInstance(Util.java:383)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1023)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:997)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:983)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:928)
at com.mysql.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:2407)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2328)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:832)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:408)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:417)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:344)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at com.company.Main.main(Main.java:11)
Caused by: java.lang.NullPointerException
at com.mysql.jdbc.ConnectionImpl.getServerCharacterEncoding(ConnectionImpl.java:3309)
at com.mysql.jdbc.MysqlIO.sendConnectionAttributes(MysqlIO.java:1985)
at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1911)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1288)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2508)
at com.mysql.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:2346)
... 13 more
The problem is the compatibility of older versions of MySQL Connector/J with MySQL 8. You need to upgrade to either MySQL Connector/J 5.1.46 or - better - 8.0.11 (or a higher version).
In my case, I was using Maven Dependency to use JDBC connector. I just changed the version of dependency. This worked for me
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.46</version>
</dependency>
Add the below version and you will be fine:
<mysql.driver.version>8.0.20</mysql.driver.version>
I have a transitime app which is maven project. When i do
mvn package -D maven.test.skip=true
it creates some jars in transitime/target folder.
It writes during packaging, that postgresql is included:
[INFO] Including postgresql:postgresql:jar:9.1-901.jdbc4 in the shaded jar.
My postgresql version is 9.1-19, so driver version is fine. i checked it.
then i run one of jars with config files, with i suppose proper database name and credentials and urls.
and i get:
WARNING: com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask#72337297 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt
exception:
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(DriverManager.java:315)
at com.mchange.v2.c3p0.DriverManagerDataSource.driver(DriverManagerDataSource.java:240)
at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:146)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:195)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:184)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:200)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1086)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1073)
at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:44)
at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1810)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:648)
It is stated that this problem is with wrong connection url or no driver.
I have configured in postgresql_hibernate.xml:
<property name="hibernate.dialect">
org.hibernate.dialect.PostgreSQLDialect
</property>
<property name="hibernate.connection.driver_class">
org.postgresql.Driver
</property>
It seems to me that maven compilation doesnt add postgresql drivers, but maven states that are included. I am new to maven but i don't know how to check or force including drivers in project. Or maybe something else for newbie is here i am missing.
When i unzipped jar that i am executing it includes org/postgresql.Driver.class.
==edit
jdbc url is: jdbc:postgresql://localhost:5432/dbname
I am working on a Java project where I make connections to an apache derby database. I have followed below -
I have downloaded Apache Derby Zip file and extracted archive to a folder.
I created environment variables DERBY_HOME, DERBY_INSTALL same way as they've asked for.
I started database server using startNetworkServer.bat in the bin directory of database folder.
I was able to connect to the database server using a Database Manager called JetBrains DataGrip. it worked fine and was able to create tables and inserted data.
But when I used the dbURL (which was used in Database Client) in my java program I'm getting ClassNotFound exception.
Here is the class path I have seen when running the database server.
D:/DevelopmentWorkspace/RunTimes/ApacheDerby10_12/db-derby-10.12.1.1-bin/lib/derby.jar;D:/DevelopmentWorkspace/RunTimes/ApacheDerby10_12/db-
derby-10.12.1.1-bin/lib/derbynet.jar;D:/DevelopmentWorkspace/RunTimes/ApacheDerby10_12/db-derby-10.12.1.1-bin/lib/derbyclient.jar;D:/Develop
mentWorkspace/RunTimes/ApacheDerby10_12/db-derby-10.12.1.1-bin/lib/derbytools.jar;D:/DevelopmentWorkspace/RunTimes/ApacheDerby10_12/db-derby
-10.12.1.1-bin/lib/derbyoptionaltools.jar
Below is the exception I'm seeing
java.lang.ClassNotFoundException: org.apache.derby.jdbc.ClientDriver
Error occurred connecting database at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
I could clearly see that derby.jdbc.ClientDriver is already there in derbyclient.jar file which was already there in classpath mentioned eariler but still I am receiving error but in Database manager its fine.
Please help.