Netbeans Persistence Unit Removal - java

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>
`

Related

Hibernate JPA - No Persistence provider for EntityManager error

I am trying to connect to sql server using JPA and hibernate with an Eclipse Maven project. I've tried moving the persistence.xml file to various locations but it doesn't seem to help.
My persistence.xml file is
<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="Trades" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
<property name="javax.persistence.jdbc.url" value="jdbc:sqlserver:/Trades\SQL00;databaseName=Trades" />
<property name="javax.persistence.jdbc.user" value="sa" />
<property name="javax.persistence.jdbc.password" value="dev" />
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/>
<property name="show_sql" value="true"/>
<property name="hibernate.temp.use_jdbc_metadata_defaults" value="false"/>
</properties>
</persistence-unit>
</persistence>
and my code is as follows and is located in src/main/resources/META-INF
public static void main(String[] args) {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("Trades");
System.out.println();
}
I have attached a screenshot which shows my eclipse set up
I solved this, turned out that Maven must have downloaded corrupt libraries - I was alerted this when I was unable to view the source for some classes in the Hibernates jars. I deleted the jars in my .m2 directory and when the jars were refreshed, it worked fine. A bit of tricky one.

Intellij IDEA Generating Persistence Mappings by database schema

I am brand new to Hibernate and I am trying to generate enitty classes, by database schema in IntelliJ IDEA Ultimate 2016.1. I create a new project with Java EE Persistence persistence.xml version 2.0, Hibernate provider and use library JPA 2.1-2.1. I have included in project library "hibernate-entitymanager-4.3.11.Final.jar".
But in Persistence tool window there is no child nodes: persistence.xml and NewPersistenceUnit. When i right-click on parent node "Generate Persistence Mappings" -> "By Databse Schema" nothing happens.
My persistence.xml file is:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
<persistence-unit name="NewPersistenceUnit">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.connection.url" value=""/>
<property name="hibernate.connection.driver_class" value=""/>
<property name="hibernate.connection.username" value=""/>
<property name="hibernate.connection.password" value=""/>
<property name="hibernate.archive.autodetection" value="class"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
<property name="hbm2ddl.auto" value="update"/>
</properties>
</persistence-unit>
</persistence>
Does anybody know why "By Database Schema" doesn't work?

No Persistence provider for EntityManager named with persistence file in correct spot

I've been searching around and haven't been able to find a working fix. My persistence.xml file is located in /src/META-INF/persistence.xml, which from looking around, this is the correct location for it.
I'm using glassfish as the server, and I keep getting the following:
javax.persistence.PersistenceException: No Persistence provider for EntityManager named pers
Here is my persistence file:
<?xml version="1.0" encoding="UTF-8"?>
<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="pers" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>cs.ee.assignment2.Client</class>
<properties>
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.archive.autodetection" value="class, hbm" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/assignment2" />
<property name="hibernate.connection.password" value="root" />
<property name="hibernate.connection.username" value="root" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
</properties>
</persistence-unit>
</persistence>
Any ideas on what the problem could be would be greatly appreciated.
Hmm.. make sure you are using PeristenceUnit not context in your entity class: see http://openejb.apache.org/jpa-concepts.html
Switch to "transaction" just to see if it fails too.
Also sometimes the old classes are not unloaded from the server properly if you are doing redeployment, you may have to shut it down and restart after redeploy.

Provider error: DatastorePersistenceProvider

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 ...

HSQLDB is eating all my memory

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

Categories

Resources