Error: "reading schema error: error calling driver#connect" when configuring Table filters in the Hibernate Reverse Engineering File (reveng.xml) - eclipse

I am having some problems trying to configure Hibernate in my Java Project. I was looking around the forum, but I could not find any solution. I am new to Hibernate, Could you please help me? Thanks in advance.
Here is my hibernate.cfg.xml file content:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="ConexionHibernate">
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password">hr</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:1521/xe</property>
<property name="hibernate.connection.username">hr</property>
<property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
</session-factory>
</hibernate-configuration>
This is how my DataBase Connection looks like in Oracle SQL Developer
This is the error itself when i try configure the tables.

In your config jdbc driver is set for mysql and also the connection url is not correct, for oracle it's:
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:#localhost:1521:xe</property>

Related

OpenJPA Exception related to JDBC Driver and connection URL in TomEE+

We are facing issue in our application with respect to the persistence configuration. The application runs on TomEE Plus (7.0) and uses Open JPA implementation. Below is the error which we are getting
<openjpa-2.4.2-r422266:1777108 nonfatal general error> org.apache.openjpa.persistence.PersistenceException: There were errors initializing your configuration: <openjpa-2.4.2-r422266:1777108 fatal user error> org.apache.openjpa.util.UserException: A connection could not be obtained for driver class "oracle.jdbc.xa.client.OracleXADataSource" and URL "jdbc:oracle:thin:#//mydburl.abc.com:1881/MYSID.ABC.COM". You may have specified an invalid URL.
We dont' get the above error when using oracle.jdbc.driver.OracleDriver. The XA driver settings were working fine on IBM WebSphere 8.5. Is there anything else which we need to configure in TomEE+ to get it working?
Update
Adding the persistence.xml file as well
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
version="1.0">
<persistence-unit name="MySchema" transaction-type="JTA">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<jta-data-source>myjndi</jta-data-source>
<class>com.abc.jpa.entity.Tuser</class>
<class>com.abc.jpa.entity.Taddress</class>
<properties>
<property name="tomee.jpa.factory.lazy" value="true"></property>
<property name="javax.persistence.jdbc.driver" value="oracle.jdbc.xa.client.OracleXADataSource" />
<property name="javax.persistence.jdbc.url"
value="jdbc:oracle:thin:#//mydburl.abc.com:1881/MYSID.ABC.COM" />
<property name="javax.persistence.jdbc.user" value="userName" />
<property name="javax.persistence.jdbc.password" value="password" />
</properties>
</persistence-unit>
</persistence>
As mentioned, it works fine if I use oracle.jdbc.driver.OracleDriver as the jdbc driver class

Hibernate mongodb configuration file

<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="hibernate.ogm.datastore.provider">mongodb</property>
<property name="hibernate.ogm.datastore.host">127.0.0.1</property>
<property name="hibernate.ogm.datastore.port">27017</property>
<property name="hibernate.ogm.datastore.database">eatery</property>
<property name="hibernate.ogm.datastore.create_database">true</property>
<mapping class="com.ws.web.models.Reservation" />
</session-factory>
</hibernate-configuration>
Does anyone know hoe to configure hibernate for mongodb. Docs says that there is no need of dialect. but i got errors
Exception in thread "main" org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:104)
at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:71)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:209)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1887)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1845)
at com.ws.web.models.Test.main(Test.java:17)
First of all i think your configuration is wrong. The proporties that you used should be placed in persistence.xml file. The example is here.
The necessary properties with description are here

Access to Derby database from another project using EclipseLink

I have a dynamic web project that creates and writes Derby database. Everything works fine. Here is the persistence.xml I used:
<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="alerts" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>test.Alert</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver" />
<property name="javax.persistence.jdbc.url" value="jdbc:derby:databases/bDb;create=true" />
<property name="javax.persistence.jdbc.user" value="user" />
<property name="javax.persistence.jdbc.password" value="user-pwd" />
<!-- EclipseLink should create the database schema automatically -->
<property name="eclipselink.ddl-generation" value="create-tables" />
<property name="eclipselink.ddl-generation.output-mode"
value="database" />
<property name="eclipselink.logging.level" value="FINEST" />
<property name="eclipselink.logging.level.sql" value="FINEST" />
</properties>
</persistence-unit>
Now I would like to create a java project that reads the same database. So I use the same persistence.xml (except that I change "create=true" to "create=false" since I don't want to create a new table). but I got this error:
[EL Severe]: ejb: 2014-12-28 22:27:20.379--ServerSession(1488953836)--Thread(Thread[DefaultQuartzScheduler_Worker-7,5,main])--Local Exception Stack:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Database 'databases/bDb' not found.
Error Code: 40000
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:331)
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:326)
at org.eclipse.persistence.sessions.DefaultConnector.connect(DefaultConnector.java:138)
at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:162)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.setOrDetectDatasource(DatabaseSessionImpl.java:204)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:741)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:239)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:685)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getAbstractSession(EntityManagerFactoryDelegate.java:204)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:304)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:336)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:302)
If I use "create=true", it will create a new database instance (it is different from the one I created from the web project). How do I fix this problem? Thanks a lot!
Since you're using a relative filename in your jdbc.url (databases/bDb), Derby is looking for the database relative to your application start directory.
And your two separate applications have two separate directories in which they are being run.
You could address this in a number of ways:
Arrange for each application to be run from the same directory
Use an absolute database path name, not a relative one, in your jdb.url value
Use the Derby Network Server configuration, not the Derby Embedded configuration
And there are undoubtedly other approaches.

accessing heroku database with hibernate eclipse plugin

I'm new to hibernate and heroku. I created a database on heroku and trying to access database with my eclipse plugin - hibernate to generate POJO classes. I'm getting error like - "Reading Schema error:Getting database metadata". I checked username, password, database name ..everything seems to be correct and I couldn't connect with PGAdmin tool ( to access Postgres database).
Can you help me in connecting heroku database with eclipse hibernate plugin ?
<?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>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.password">xxxxxx</property>
<property name="hibernate.connection.url">jdbc:postgresql://xxxxx:5432/xxxxx</property>
<property name="hibernate.connection.username">xxxxxxx</property>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.default_schema">xxxxxx</property>
</session-factory>
Any help is appreciated !
I found solution for my question. I have to use ssl connection, so the url is:
<property name="hibernate.connection.url">jdbc:postgresql://xxxx-host-xxxx:5432/xxx-database-xxx?sslfactory=org.postgresql.ssl.NonValidatingFactory&ssl=true</property>
Install Heroku Toolbelt and then type heroku config. Take each part of the DATABASE_URL in this form: postgres://username:password#host:port/dbname
This works fine with PGAdmin and should work with any other Postgres-compatible tool. Note that Heroku often uses non-standard ports.

How do I configure OpenJPA SQL logging?

What is the OpenJPA configuration to view SQL query executed in a database? I would like to view the query with all parameters executed in log or console instead of viewing the JPQL query
<property name="openjpa.Log" value="SQL=Trace" />
Enables logging of all SQL statements, minus parameter values.
<property name="openjpa.ConnectionFactoryProperties" value="PrintParameters=true" />
Enables logging of SQL parameters.
Logging documentation
If you're using log4j, you can setup your log4j.properties file as follows, which will display both the native SQL query and any parameters:
log4j.rootLogger=WARN, CONSOLE
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%-5p %t %d{ISO8601} %l - %m%n
log4j.category.openjpa.jdbc.SQL=TRACE
To configure Open JPA for Log4J, you need to do the following in persistence xml
Open JPA Configurations
{'property name=”openJpa.Log” value=”log4j”'}
Log4j properties for Open JPA configs
log4j.logger.openjpa.Query=TRACE
log4j.logger.openjpa.jdbc.SQL=TRACE
http://openjpa.apache.org/builds/1.0.1/apache-openjpa-1.0.1/docs/manual/ref_guide_logging_log4j.html
Hi I want to add running persistance.xml file
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="EHS_PU">
<jta-data-source>mysqlDataSource</jta-data-source>
<class>com.ap.entity.EHSDo</class>
<class>com.ap.entity.EventDo</class>
<properties>
<property name="openjpa.Log" value="log4j" />
<property name="openjpa.ConnectionFactoryProperties" value="PrintParameters=true" />
</properties>
</persistence-unit>
</persistence>
In addition to Rick's answer, there is also the "openjpa.ConnectionFactory2Properties" property for connection factories used for unmanaged connections. (more details here: https://openjpa.apache.org/builds/1.2.3/apache-openjpa/docs/ref_guide_conf_openjpa.html#openjpa.ConnectionFactory2Properties)