I'm working on project(REST) where I use hibernate with glassfish. I try to get list of data from DB, but I get this error:
javax.persistence.PersistenceException: Exception [EclipseLink-4021] (Eclipse Persistence Services - 2.0.1.v20100213-r6600): org.eclipse.persistence.exceptions.DatabaseException
Exception Description: Unable to acquire a connection from driver [null], user [null] and URL [null]. Verify that you have set the expected driver class and URL. Check your login, persistence.xml or sessions.xml resource. The jdbc.driver property should be set to a class that is compatible with your database platform
note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 3.0.1 logs.
PERSISTENCE.XML
<?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="manager1"
transaction-type="RESOURCE_LOCAL">
<properties>
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.format_sql" value="false" />
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
<property name="hibernate.connection.url"
value="jdbc:mysql://url" />
<property name="hibernate.connection.username" value="admin" />
<property name="hibernate.connection.password" value="admin" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.hbm2ddl.auto" value="create-update" />
UPDATE:
Connection to hibernate works, because I tested it in console.
Is it possible that Hibernate requires another config file for hibernate?
Thanks for help :)
Related
I have a project where we use Hibernate-jpa-2.1 and get an EntityManager istance both in this way
#PersistenceContext(unitName = "common-api")
EntityManager em;
and this
em = Persistence.createEntityManagerFactory("common-api").createEntityManager();
because some classes aren't EJB and others are (I guess). The problem is that the createEntityManagerFactory fails with the error:
Caused by: javax.persistence.PersistenceException: Invalid persistence.xml.
Error parsing XML [line : -1, column : -1] : cvc-complex-type.2.4.a: Invalid content was found starting with element 'class'. One of '{"http://xmlns.jcp.org/xml/ns/persistence":validation-mode, "http://xmlns.jcp.org/xml/ns/persistence":properties}' is expected.
at org.hibernate.jpa.boot.internal.PersistenceXmlParser.validate(PersistenceXmlParser.java:357)
at org.hibernate.jpa.boot.internal.PersistenceXmlParser.loadUrl(PersistenceXmlParser.java:290)
at org.hibernate.jpa.boot.internal.PersistenceXmlParser.parsePersistenceXml(PersistenceXmlParser.java:94)
at org.hibernate.jpa.boot.internal.PersistenceXmlParser.doResolve(PersistenceXmlParser.java:84)
at org.hibernate.jpa.boot.internal.PersistenceXmlParser.locatePersistenceUnits(PersistenceXmlParser.java:66)
at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:80)
... 80 more
This is the persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="common-api" transaction-type="JTA">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<jta-data-source>(...)</jta-data-source>
<class>(the only entity we have in this Maven module)</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
<validation-mode>NONE</validation-mode>
<properties>
<property name="javax.persistence.validation.mode" value="NONE" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL57InnoDBDialect" />
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.order_updates" value="true" />
<property name="hibernate.max_fetch_depth" value="2" />
<property name="hibernate.use_sql_comments" value="true" />
<property name="hibernate.use_identifer_rollback" value="true" />
<property name="hibernate.jdbc.batch_size" value="0" />
<property name="hibernate.jdbc.batch_versioned_data" value="false" />
<property name="hibernate.jdbc.use_get_generated_keys" value="true" />
<property name="hibernate.hbm2ddl.auto" value="none"/>
</properties>
</persistence-unit>
</persistence>
I don't understand why this happens because my classes are in the same package, same maven module, use the same Hibernate entities and the same persistence.xml.
N.B.: Making this class an EJB isn't an option.
This is an error you should only get if the element order is wrong (and not the same as you posted here). The order of elements in persistence.xml is important during validation. It's described in the xsd. In each persistence-unit it is as follows:
description
provider
jta-data-source
non-jta-data-source
mapping-file
jar-file
class
exclude-unlisted-classes
shared-cache-mode
validation-mode
properties
When i tried to deploy an application in weblogic, he give-me the follow exception:
Substituted for missing class Exception [EclipseLink-7298] (Eclipse
Persistence Services - 2.6.5.v20170607-b3d05bd) -
org.eclipse.persistence.exceptions.ValidationException Exception
Description: The mapping [associated] from the embedded ID class
[class br.com.webproj.web.model.associated.pk.AssmaintainPK] is an
invalid mapping for this class. An embeddable class that is used with
an embedded ID specification (attribute [AssmaintainPK] from the
source [class br.com.webproj.web.model.associated.AssMaintain]) can
only contain basic mappings. Either remove the non basic mapping or
change the embedded ID specification on the source to be embedded.
In my persistence.xml i have:
<?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="Web_PU">
<jta-data-source>JDBC/WEB</jta-data-source>
<jar-file>web-Model.jar</jar-file>
<shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
<properties>
<property name="hibernate.dialect"
value="org.hibernate.dialect.Oracle10gDialect" />
<property name="hibernate.hbm2ddl.auto" value="none" />
<property name="hibernate.show_sql" value="false" />
<!-- Cache Enabled -->
<property name="hibernate.cache.use_second_level_cache"
value="true" />
<property name="hibernate.cache.use_query_cache"
value="true" />
<property name="hibernate.cache.region.factory_class"
value="org.hibernate.cache.infinispan.JndiInfinispanRegionFactory" />
<property name="hibernate.cache.infinispan.cachemanager"
value="java:jboss/infinispan/container/hibernate" />
<property name="hibernate.transaction.manager_lookup_class"
value="org.hibernate.transaction.JBossTransactionManagerLookup" />
<property name="hibernate.cache.infinispan.statistics"
value="true" />
<!-- I TRIED INCLUDING THIS, BUT NOT SOLVE -->
<property name="eclipselink.exclude-eclipselink-orm"
value="false" />
<property name="eclipselink.orm.throw.exceptions"
value="false" />
<property name="eclipselink.orm.validate.schema"
value="false" />
</properties>
</persistence-unit>
</persistence>
I think this error occurs because the weblogic use the eclipse link, and the project an other version of jpa. But the error is in a jar included in project and i cant change and see the code. If the problem is this, what i can do to dont use the eclipse link of weblogic (obs: in JBoss the project runs normally).
I am getting above exception when trying to do a simple example using openjpa. Here I am using a custom persistance provider class. Following is my persistence.xml file. I went through the previous similar threads but couldn't find a proper solution with my configurations.
persistence.xml
<?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="juddiDatabase" transaction-type="RESOURCE_LOCAL">
<provider>org.juddi.test.persistance.JUDDIPersistenceProviderImpl</provider>
<mapping-file>META-INF/orm.xml</mapping-file>
<!-- entity classes -->
<class>org.apache.juddi.model.Address</class>
<class>org.apache.juddi.model.AddressLine</class>
<class>org.apache.juddi.model.AuthToken</class>
<class>org.apache.juddi.model.BindingCategoryBag</class>
<class>org.apache.juddi.model.BindingDescr</class>
<class>org.apache.juddi.model.BindingTemplate</class>
<class>org.apache.juddi.model.BusinessCategoryBag</class>
<class>org.apache.juddi.model.BusinessDescr</class>
<class>org.apache.juddi.model.BusinessEntity</class>
<class>org.apache.juddi.model.BusinessIdentifier</class>
<class>org.apache.juddi.model.BusinessName</class>
<class>org.apache.juddi.model.BusinessService</class>
<class>org.apache.juddi.model.CategoryBag</class>
<class>org.apache.juddi.model.Clerk</class>
<class>org.apache.juddi.model.ClientSubscriptionInfo</class>
<class>org.apache.juddi.model.Contact</class>
<class>org.apache.juddi.model.ContactDescr</class>
<class>org.apache.juddi.model.DiscoveryUrl</class>
<class>org.apache.juddi.model.Email</class>
<class>org.apache.juddi.model.InstanceDetailsDescr</class>
<class>org.apache.juddi.model.InstanceDetailsDocDescr</class>
<class>org.apache.juddi.model.KeyedReference</class>
<class>org.apache.juddi.model.KeyedReferenceGroup</class>
<class>org.apache.juddi.model.Node</class>
<class>org.apache.juddi.model.OverviewDoc</class>
<class>org.apache.juddi.model.OverviewDocDescr</class>
<class>org.apache.juddi.model.PersonName</class>
<class>org.apache.juddi.model.Phone</class>
<class>org.apache.juddi.model.Publisher</class>
<class>org.apache.juddi.model.PublisherAssertion</class>
<class>org.apache.juddi.model.PublisherAssertionId</class>
<class>org.apache.juddi.model.ServiceCategoryBag</class>
<class>org.apache.juddi.model.ServiceDescr</class>
<class>org.apache.juddi.model.ServiceName</class>
<class>org.apache.juddi.model.ServiceProjection</class>
<class>org.apache.juddi.model.ServiceProjectionId</class>
<class>org.apache.juddi.model.Subscription</class>
<class>org.apache.juddi.model.SubscriptionChunkToken</class>
<class>org.apache.juddi.model.SubscriptionMatch</class>
<class>org.apache.juddi.model.Tmodel</class>
<class>org.apache.juddi.model.TmodelCategoryBag</class>
<class>org.apache.juddi.model.TmodelDescr</class>
<class>org.apache.juddi.model.TmodelIdentifier</class>
<class>org.apache.juddi.model.TmodelInstanceInfo</class>
<class>org.apache.juddi.model.TmodelInstanceInfoDescr</class>
<class>org.apache.juddi.model.TransferToken</class>
<class>org.apache.juddi.model.TransferTokenKey</class>
<class>org.apache.juddi.model.UddiEntity</class>
<class>org.apache.juddi.model.UddiEntityPublisher</class>
<properties>
<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/>
<property name="openjpa.Log" value="DefaultLevel=ERROR, Tool=ERROR"/>
<property name="openjpa.jdbc.UpdateManager" value="operation-order"/>
<property name="openjpa.RuntimeUnenhancedClasses" value="warn"/>
<!-- h2 connection properties -->
<property name="openjpa.ConnectionDriverName" value="org.h2.Driver"/>
<property name="openjpa.ConnectionURL" value="jdbc:h2:repository/database/juddiv3"/>
<property name="openjpa.ConnectionUserName" value="test"/>
<property name="openjpa.ConnectionPassword" value="test"/>
<!-- mysql connection properties
<property name="openjpa.ConnectionURL" value="jdbc:mysql://localhost:3306/juddi"/>
<property name="openjpa.ConnectionDriverName" value="com.mysql.jdbc.Driver"/>
<property name="openjpa.ConnectionUserName" value="juddiv3"/>
<property name="openjpa.ConnectionPassword" value=""/>
-->
<property name="openjpa.Compatibility" value="CheckDatabaseForCascadePersistToDetachedEntity=true"/>
</properties>
</persistence-unit>
</persistence>
And I am getting the following error
org.apache.openjpa.persistence.ArgumentException: A JDBC Driver or DataSource class name must be specified in the ConnectionDriverName property. Available properties in configuration are "org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl#442ce698".
at org.apache.openjpa.jdbc.schema.DataSourceFactory.newDataSource(DataSourceFactory.java:72)
at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.createConnectionFactory(JDBCConfigurationImpl.java:844)
at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getDBDictionaryInstance(JDBCConfigurationImpl.java:602)
at org.apache.openjpa.jdbc.meta.MappingRepository.endConfiguration(MappingRepository.java:1510)
at org.apache.openjpa.lib.conf.Configurations.configureInstance(Configurations.java:518)
at org.apache.openjpa.lib.conf.Configurations.configureInstance(Configurations.java:443)
at org.apache.openjpa.lib.conf.PluginValue.instantiate(PluginValue.java:104)
at org.apache.openjpa.conf.MetaDataRepositoryValue.instantiate(MetaDataRepositoryValue.java:68)
at org.apache.openjpa.lib.conf.ObjectValue.instantiate(ObjectValue.java:83)
at org.apache.openjpa.conf.OpenJPAConfigurationImpl.newMetaDataRepositoryInstance(OpenJPAConfigurationImpl.java:968)
at org.apache.openjpa.conf.OpenJPAConfigurationImpl.getMetaDataRepositoryInstance(OpenJPAConfigurationImpl.java:959)
at org.apache.openjpa.kernel.AbstractBrokerFactory.makeReadOnly(AbstractBrokerFactory.java:638)
at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:203)
at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:156)
at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:227)
at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:154)
at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:60)
at org.apache.juddi.config.PersistenceManager.getEntityManager(PersistenceManager.java:45)
at org.apache.juddi.config.AppConfig.getPersistentConfiguration(AppConfig.java:109)
at org.apache.juddi.config.AppConfig.loadConfiguration(AppConfig.java:95)
at org.apache.juddi.config.AppConfig.<init>(AppConfig.java:62)
at org.apache.juddi.config.AppConfig.getInstance(AppConfig.java:183)
at org.apache.juddi.config.AppConfig.getConfiguration(AppConfig.java:205)
at org.apache.juddi.Registry.start(Registry.java:55)
in your persistence.xml config file you have several datasource descriptions (MySQL and H2). Delete one of them and try again.
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.
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?