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"/>
Related
I'm writing a database synchronization tool for existing databases. One of the requirement is to validate the entities with the database schema. The program has to be aware of any database changes (like adding new columns to the database). I'm planning on using Hibernate for this project.
Is there anyway Hibernate can validate the difference between the entity and the table in the database?
Can Hibernate output SQL script so I can review the SQL script before running it to update the target database?
Yes hibernate can output the SQL in the logs.
You need to set the : - <property name="hibernate.show_sql" value="true"/>
but SQL generated by the server is little messy so you have to modify the column name as per your database table.
please have a look at the following XML of my project with the hibernate
<?xml version="1.0" encoding="UTF-8"?>
<persistence 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"
version="2.0">
<persistence-unit name="communityPortalPersitenceUnit">
<class>com.googlecode.frameworksintegration.domain.Blog</class>
<properties>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/conhint_prod" />
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
<property name="hibernate.connection.username" value="root" />
<property name="hibernate.connection.password" value="admin" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />
<property name="hibernate.connection.zeroDateTimeBehavior" value="convertToNull"/>
<property name="hibernate.show_sql" value="true"/>
<!--Start :- connection pooling -->
<property name="hibernate.connection.provider_class" value="org.hibernate.connection.C3P0ConnectionProvider" />
<property name="hibernate.c3p0.max_size" value="100" />
<property name="hibernate.c3p0.min_size" value="0" />
<property name="hibernate.c3p0.acquire_increment" value="1" />
<property name="hibernate.c3p0.idle_test_period" value="300" />
<property name="hibernate.c3p0.max_statements" value="0" />
<property name="hibernate.c3p0.timeout" value="100" />
<!--End :- connection pooling -->
</properties>
</persistence-unit>
</persistence>
I created a Persistence Unit in Netbeans and have since deleted the Persistence.xml file. Now whenever I run my project, I get tonnes of errors like "No Persistence provider for EntityManager named Hi__Score_OldPU". How can I get rid of my Persistence Unit entirely?
That error happen when persistence.xml is at the wrong place (Project-->WebContent-->META-INF-->persistence.xml).
It should be here (src-->META-INF-->persistence.xml)
If that folder doesn't exist you can create a folder "META-INF" at src and put persistence.xml on it.
here my persistence.xml look like this.
`
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="livraria" transaction-type ="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>br.com.k19.modelo.Editora</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/K21_livraria_bd"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.password" value="root"/>
</properties>
</persistence-unit>
`
I'm trying to convert my hibernate-based GWT implementation into a JPA2 version. I've added the persistence.xml, the specific libraries and added some code just to open (by getting an entityManager). I just do a local employment, I do not use google's app engine (and I'm not intended to use it).
I get the following message:
Cannot connect to MySQL database
server (Provider error. Provider:
org.datanucleus.store.appengine.jpa.DatastorePersistenceProvider),
exiting
My persistence.xml looks like:
<?xml version="1.0" encoding="UTF-8"?>
<persistence
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_1_0.xsd"
version="1.0">
<persistence-unit name="mydatabase_dev">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>mypackage.Product</class>
<class>mypackage.Expert</class>
<class>mypackage.Person</class>
<properties>
<property name="hibernate.archive.autodetection" value="class, hbm"/>
<property name="hibernate.show_sql" value="false"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.url" value="jdbc:mysql://myhost.mydomain/MYDATABASE"/>
<property name="hibernate.connection.username" value="myusername"/>
<property name="hibernate.connection.password" value="topsecret"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.c3p0.min_size" value="5"/>
<property name="hibernate.c3p0.max_size" value="20"/>
<property name="hibernate.c3p0.timeout" value="300"/>
<property name="hibernate.c3p0.max_statements" value="50"/>
<property name="hibernate.c3p0.idle_test_period" value="3000"/>
<!-- Disable the second-level cache -->
<property name="cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/>
</properties>
</persistence-unit>
</persistence>
There is no other error message, warning, stacktrace, etc.
What is wrong or in what way can I examine what the real problem is?
GAE/J doesn't do MySQL, nor JPA2 so why are you including it/specifying it in your persistence.xml? Perhaps if you post your persistence.xml then people can make an informed opinion ...
I'm having some problem with EclipseLink. I'm using GlassFish v3.1 and I'm trying to use EclipseLink for my persistence layer. I followed all tutorials available on the Eclipse wiki without luck. My persistence.xml file cannot be parsed and I receive this error while trying to create the EntityManagerFactory:
org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while processing persistence.xml from URL: bundle://307.1:1/
Here is my persistence.xml located in /WEB-INF/classes/META-INF/:
<persistence version="1.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_1_0.xsd">
<persistence-unit name="generic">
<class>com.generic.domain.Service</class>
<properties>
<!-- Embedded MySQL Login -->
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306"/>
<!-- TODO: replace with connection pool -->
<property name="javax.persistence.jdbc.userid" value="root"/>
<property name="javax.persistence.jdbc.password" value=""/>
<property name="eclipselink.target-database" value="MySQL"/>
<property name="eclipselink.jdbc.read-connections.min" value="1"/>
<property name="eclipselink.jdbc.write-connections.min" value="1"/>
<property name="eclipselink.jdbc.batch-writing" value="JDBC"/>
<!-- Logging Settings -->
<property name="eclipselink.logging.level" value="FINE" />
<property name="eclipselink.logging.thread" value="false" />
<property name="eclipselink.logging.session" value="false" />
<property name="eclipselink.logging.exceptions" value="true" />
<property name="eclipselink.logging.timestamp" value="false"/>
</properties>
</persistence-unit>
</persistence>
I added this line to my MANIFEST.MF:
JPA-PersistenceUnits: generic
I can now confirm that it's a bug in EclipseLink. The work around to your problem is to either get hold of EntityManagerFactory using JNDI lookup or #PersistenceUnit instead of doing Persistence.createEntityManagerFactory().
1) It looks like you are trying to use OSGi/JPA from your WAB. Correct?
2) Can you tell if you have installed any new eclipselink bundles in your system? If so, what are they?
3) Can you provide stack trace?
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