i am using Java Eclipse oxygen and Mysql for Database. I am trying to Persist data on my sql. It says "Loading class com.mysql.jdbc.Driver'. This is deprecated. The new driver class iscom.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary." how can it be solved? Thank you.
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/studentdata"/>
<property name="javax.persistence.jdbc.user" value=""/>
<property name="javax.persistence.jdbc.password" value=""/>
<property name="eclipselink.logging.level" value="SEVERE"/>
<property name="eclipselink.ddl-generation" value="create-or-extend-tables"/>
</properties>
Remove
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
The ServiceLoader mechanisme will find the driver by its own.
Related
My Java Servlet application currently has the database connection parameters hard-coded in the persistence.xml file like this:
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/XXX?useEncoding=true&characterEncoding=UTF-8"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.user" value="XXX"/>
<property name="javax.persistence.jdbc.password" value="XXX"/>
<property name="eclipselink.ddl-generation" value="create-tables"/>
</properties>
I'd like to move those out to a separate configuration file so that users can change them on their own. What's the way to do that?
In a JPA project when using the postgresql driver the tables are auto generated. When i switch to the h2 database driver, I get errors, that the tables are not found. This let me assume, that the tables are not generated.
Postgresql Config
<persistence-unit name="postgresql" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>...</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:postgresql://127.0.0.1/example"/>
<property name="javax.persistence.jdbc.password" value="example"/>
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/>
<property name="javax.persistence.jdbc.user" value="example"/>
<property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
</properties>
</persistence-unit>
h2 config
<persistence-unit name="OntoJobTestDB" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>...</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.h2.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:test" />
<property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
<property name="eclipselink.ddl-generation.output-mode" value="database" />
</properties>
</persistence-unit>
It turned out, that the tables could not have been found, because they were never created. An early error caused by a #Converter annotation, which was postgresql specific prevented the creation of the tables.
My advice is to always double check the debug output.
I want to create a dynamic time table using pure JPA 2. Like in hibernate we create the dynamic table using SchemaExport.
The code:
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/employee;create=true"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.password" value="root"/>
<property name = "hibernate.show_sql" value = "true" />
<properties>
The following exception occur when I use create=true:
WARN: HHH000342: Could not obtain connection to query metadata : Unknown database 'employee;create=true'
Exception in thread "main" javax.persistence.PersistenceException: [PersistenceUnit: EmployeeService] Unable to build EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:915)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:890)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:57)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)
You can specify create=true in persistence.xml url.
<persistence-unit name="PU" transaction-type="RESOURCE_LOCAL">
...
<properties>
---
<property name="javax.persistence.jdbc.url"
value="jdbc:???://localhost:port/DBName;create=true"/>
<property name="javax.persistence.jdbc.user" value="user"/>
<property name="javax.persistence.jdbc.password" value="pwd"/>
</properties>
</persistence-unit>
</persistence>
I am using this method in the following way
EntityManagerFactory emftemp = Persistence.createEntityManagerFactory("XYZ");
and my persistence.xml has the following entry for this unit
<persistence-unit name="XYZ" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="hibernate.show_sql" value="false"/>
<property name="hibernate.hbm2ddl.auto" value="validate"/>
<property name="hibernate.query.substitutions" value="true=1, false=0"/>
<property name="hibernate.connection.driver_class" value="oracle.jdbc.driver.OracleDriver"/>
<property name="hibernate.connection.url" value="jdbc:oracle:thin:#aesop-db.corp.nlg1.com:1521:TLCSDEV4"/>
<property name="hibernate.connection.username" value="abcd"/>
<property name="hibernate.connection.password" value="abcd"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle9iDialect"/>
<property name="hibernate.connection.timeout" value="120"/>
<property name="hibernate.connection.provider_class" value="org.hibernate.connection.C3P0ConnectionProvider" />
<property name="hibernate.c3p0.min_size" value="2"/>
<property name="hibernate.c3p0.max_size" value="2"/>
<property name="hibernate.c3p0.idle_test_period" value="60"/>
</properties>
</persistence-unit>
This is a Java application and I am using the hibernate3.jar and I am using ejb3-persistence.jar and JDK1.5.
The problem is that everytime I run the application, it hangs on this call . Its not throwing any exception or error . It just hangs at that point.
Can anyone help in identifying why it does not move forward ?
Two thoughts:
When something hangs it's often IO/networking issues to blame. So, try to make sure that the DB is really alive, and that you can connect to it from your computer.
This could be a duplicate of Persistence.createEntityManagerFactory takes ages
I had this same issue against an Oracle 11g database with only three entities defined but a very large DB. After commenting out the following line from persistence.xml, the issue was resolved.
<property name="hibernate.hbm2ddl.auto" value="update"/>
I'm using a HSQLDB for an application that stores research data and there is quite a lot of data. HSQLDB insists on always loading the tables into memory. I've tried fixing this by setting hsqldb.default_table_type=cached in my persistence.xml but that does not work.
Is this the wrong place?
persistence.xml
<persistence-unit name="Dvh DB" transaction-type="RESOURCE_LOCAL">
<class>com.willcodejavaforfood.dvh.entity.Patient</class>
<class>com.willcodejavaforfood.dvh.entity.Plan</class>
<class>com.willcodejavaforfood.dvh.entity.Dvh</class>
<class>com.willcodejavaforfood.dvh.entity.ImportSession</class>
<class>com.willcodejavaforfood.dvh.entity.Project</class>
<class>com.willcodejavaforfood.dvh.entity.Course</class>
<class>com.willcodejavaforfood.dvh.entity.Property</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:hsqldb:./myDvhDb"/>
<property name="javax.persistence.jdbc.user" value="sa"/>
<property name="javax.persistence.jdbc.password" value=""/>
<property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" />
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
<property name="hsqldb.default_table_type" value="cached" />
</properties>
</persistence-unit>
When my HSQLDB database is created I can see in its properties file:
hsqldb.default_table_type=memory
Thanks
Could you try putting the hsqldb.default_table_type=cached in the connection string? Like this: jdbc:hsqldb:./myDvhDb;hsqldb.default_table_type=cached