Where persistence.xml should be? - java

I'm trying to figure out why my Java program returns me "No persistence provider for EntityManager name WroProjectPU"
I'm thinking it's happening because Java can't find persistence.xml file.
I tried to use different configurations, but no one worked.
Currently, the structure of my program is looking like this:
where selected Main.java file is the file, where I have
EntityManagerFactory emf =
Persistence.createEntityManagerFactory("WroProjectPU");
The main folder WroProject is under this absolute location:
C:\Users\Szymon\workspace\WroProject
Could you tell me where I should put my persistence.xml file? The full absolute path please.
Thanks in advance!
AFTER EDIT:
My persistence.xml looks like this:
<?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="WroProjectPU" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>db.User</class>
<class>db.Session</class>
<class>db.Email</class>
<class>db.File</class>
<class>db.FilePermission</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/wroproject"/>
<property name="javax.persistence.jdbc.password" value="postgres"/>
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/>
<property name="javax.persistence.jdbc.user" value="postgres"/>
</properties>
The problem:
lis 24, 2014 9:30:31 PM org.hibernate.ejb.HibernatePersistence logDeprecation
WARN: HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
lis 24, 2014 9:30:31 PM org.hibernate.ejb.HibernatePersistence logDeprecation
WARN: HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
lis 24, 2014 9:30:31 PM org.hibernate.ejb.HibernatePersistence logDeprecation
WARN: HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named WroProjectPU
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:61)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
at wroproject.Main.main(Main.java:18)
Java Result: 1

Related

How to connect Hibernate with MySQL

I want to connect Hibernate with MySQL. I tried all methods, but I'm still getting this error. I'm using Hibernate the version.
avr. 19, 2018 1:55:21 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.2.16.Final}
avr. 19, 2018 1:55:21 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
avr. 19, 2018 1:55:22 PM org.hibernate.boot.jaxb.internal.stax.LocalXmlResourceResolver resolveEntity
WARN: HHH90000012: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/hibernate-mapping. Use namespace http://www.hibernate.org/dtd/hibernate-mapping instead. Support for obsolete DTD/XSD namespaces may be removed at any time.
avr. 19, 2018 1:55:24 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
avr. 19, 2018 1:55:24 PM org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator initiateService
WARN: HHH000181: No appropriate connection provider encountered, assuming application will be supplying connections
avr. 19, 2018 1:55:24 PM org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator initiateService
WARN: HHH000342: Could not obtain connection to query metadata : The application must supply JDBC connections
Exception in thread "main" org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:271)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:233)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:242)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:352)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:111)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83)
at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:418)
at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:87)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:691)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:726)
at TestHibernate1.main(TestHibernate1.java:14)
Caused by: 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:100)
at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:54)
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:137)
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:259)
===========================================================================
=> this is my hibernate.cfg.xml
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">net.sf.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/bd_per</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password"></property>
<property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property>
<mapping resource="Personnes.hbm.xml"/>
</session-factory>
</hibernate-configuration>
=> this is my hibernate-mapping
<?xml version="1.0"?><!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping"><hibernate-mapping>
<class name="Personnes" table="personnes">
<id name="idPersonne" type="int" column="idpersonne">
<generator class="native"/>
</id>
<property name="nomPersonne" type="string" not-null="true" />
<property name="prenomPersonne" type="string" not-null="true" />
</class>
</hibernate-mapping>
=> finaly my classe Personnes
public class Personnes {
private Integer idPersonne;
private String nomPersonne;
private String prenomPersonne;
public Personnes(String nomPersonne, String prenomPersonne) {
this.nomPersonne = nomPersonne;
this.prenomPersonne = prenomPersonne;
}
public Personnes() {
}
public Integer getIdPersonne() {
return idPersonne;
}
public String getNomPersonne() {
return nomPersonne;
}
public String getPrenomPersonne() {
return prenomPersonne;
}
public void setIdPersonne(Integer integer) {
idPersonne = integer;
}
And,thanks for responding as quickly as possible.
public void setPrenomPersonne(String string) {
prenomPersonne = string;
}
public void setNomPersonne(String string) {
// TODO Auto-generated method stub
}
}
At least you need to use dialect from this package https://docs.jboss.org/hibernate/orm/3.5/api/org/hibernate/dialect/package-summary.html not from net.sf.hibernate.dialect. For example org.hibernate.dialect.MySQL5Dialect
The package you use was in old hibernate version.
And why do you use xml-style definition?
The proper hibernate dialect needs to be selected depending on the version of MySQL. I faced similar issue and resolution was very simple of using InnoDB dialect version of MySQL.
You can refer the proper dialect from package: org.hibernate.dialect
Referece : Link

Can't configure JPA with Intellij

Im trying to configure a simple JPA project and I'm very stuck.
I have a working dataSource (MySQL) & GlassFish with multiple tables.
I did the following steps (all of the files generated by Intellij):
Create new project with Java EE Persistance with Hibernate Provider.
Import DB that has a Student table.
Generate Entity classes with Intellij IDE.
Import Hibernate-entitymanager library from Maven.
Import MySQL connector.
Try to run a simple JPA program to create new row but I get an exeption :
No Persistence provider for EntityManager named persistenceUnit
What can be the problem? I tried almost every tutorial and every question here but with no success!
Please Help me!
(sometimes the Hibernate in the persistance provider is colored red)
persistance:
<?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>
<class>modules.CourseEntity</class>
<class>modules.StuCouEntity</class>
<class>modules.StudentsEntity</class>
<class>modules.TeacherEntity</class>
<properties>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.username" value="root"/>
<property name="hibernate.connection.password" value="123456"/>
<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>
Main.java:
import modules.StudentsEntity;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
public class MainClass
{
public static void main(String[] args)
{
StudentsEntity stu = new StudentsEntity();
stu.setName("David");
EntityManagerFactory emf = Persistence.createEntityManagerFactory("persistenceUnit");
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
try
{
em.persist(stu);
em.getTransaction().commit();
}
catch (Exception ex)
{
System.out.println(ex.getMessage());
ex.printStackTrace();
em.getTransaction().rollback();
}
finally
{
em.close();
}
}
}
error:
June 16, 2017 5:47:07 PM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
June 16, 2017 5:47:07 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.1.5.Final}
June 16, 2017 5:47:07 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
June 16, 2017 5:47:07 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named persistenceUnit
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:84)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
at MainClass.main(MainClass.java:17)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
You defined
<persistence-unit name="NewPersistenceUnit">
while tryng to call Persistence.createEntityManagerFactory("persistenceUnit");
change NewPersistenceUnit to persistenceUnit

No persistence provider for entitymanager named xyz

I have a JavaFX Maven project in IntelliJ, which uses Hibernate. When the app is starting, I am getting the following error message:
No persistence provider for entitymanager named xyz
Why? My META-INF/persistence.xml is located in myproject/src/main/resources (the directory is checked as resource folder in project settings).
I am sure I've downloaded all Hibernate JARs via Maven.
My persistence.xml is correct:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="xyz">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>entity.User</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLiteDialect"/>
<property name="javax.persistence.jdbc.url" value="jdbc:sqlite:java.sqlite"/>
<property name="javax.persistence.jdbc.driver_class" value="oracle.jdbc.driver"/>
<property name="hibernate.hbm2ddl.auto" value="none"/>
<property name="hibernate.show_sql" value="false"/>
<property name="javax.persistence.schema-generation.database.action" value="create"/>
</properties>
</persistence-unit>
</persistence>
Java code:
factory = Persistence.createEntityManagerFactory("xyz");
In my an old non-Maven project the code above worked fine.
your persistence.xml must be located in the META-INF folder
There was a different context and solution in my case:
Context:
see the log below:
org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [org.h2.Driver] at URL [jdbc:h2:tcp://localhost/~/test]
org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {user=sa}
org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl$PooledConnections <init>
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
...
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named NewPersistenceUnit`
Solution:
As its clear from logs above, persistenceUnit has been found and some data like dialect, username and password is extracted.
There was problem in mapping of entities. By commenting out #Entity one by one on entities, I was able to find the problem and solve it, without any change in persistence.xml file.
I have no idea why error like No Persistence provider for EntityManager named X should be shown when there is a problem in entity mapping!

Hibernate Warning about PersistenceProvider occurs even if correct provider is given

When I am trying to use Hibernate with a local Derby-Database, I always get a Warning about the wrong persistence provider three times:
[WARN] HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
[WARN] HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
[WARN] HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
I can't find any reason for this, because my persistence.xml (which is the only persistence.xml in the project) looks like this:
<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="performanzdb" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>...</class>
<properties>
<property name="hibernate.connection.url" value="myUrl;create=true" />
<property name="hibernate.connection.driver_class" value="org.apache.derby.jdbc.EmbeddedDriver" />
<property name="hibernate.dialect" value="org.hibernate.dialect.DerbyDialect" />
<property name="hibernate.hbm2ddl.auto" value="update" />
</properties>
</persistence-unit>
</persistence>
and therefore defines the correct persistence provider org.hibernate.jpa.HibernatePersistenceProvider.
Another reason I could imagine is that some of my maven dependencies are wrong, but these are just the most recent entitymanager- and jpamodelgen-dependencies:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.7.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>4.3.7.Final</version>
</dependency>
Besides the warning in the beginning and the error:
[ERROR] HHH015011: Unable to locate static metamodel field : package.class_#field
occurring for newly defined fields from time to time, Hibernate runs fine and everything is written in the database as it should.
Does anyone know, why the wrong PersistenceProvider is used or why this error occurs?
similar problem has been reported here, please have a look.
from the above links,
This bug also affects version 4.3.7.Final.
With a new maven-based Spring Boot project including JPA depencencies, I still see these warning log lines when slf4j level is INFO.
14:04:47.990 [main] WARN o.hibernate.ejb.HibernatePersistence - HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
14:04:47.990 [main] WARN o.hibernate.ejb.HibernatePersistence - HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
14:04:47.990 [main] WARN o.hibernate.ejb.HibernatePersistence - HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
I found this solution https://hibernate.atlassian.net/browse/HHH-9141 and added a snippet of code to just before creating the entity manager factory:
public EntityManager create() {
if (AbstractBaseForJUnit.EMF == null) {
PersistenceProviderResolverHolder.setPersistenceProviderResolver(new PersistenceProviderResolver() {
private final List<PersistenceProvider> providers_ = Arrays.asList((PersistenceProvider) new HibernatePersistenceProvider());
#Override
public void clearCachedProviders() {
// TODO Auto-generated method stub
}
#Override
public List<PersistenceProvider> getPersistenceProviders() {
return providers_;
}
});
if (StringUtils.isBlank(AbstractBaseForJUnit.PU_NAME)) {
AbstractBaseForJUnit.PU_NAME = CoreProperties.Features.PERSISTENCE_UNIT_NAME;
}
AbstractBaseForJUnit.EMF = Persistence.createEntityManagerFactory(AbstractBaseForJUnit.PU_NAME);
}
if (this.EM == null) {
this.EM = AbstractBaseForJUnit.EMF.createEntityManager();
this.EM.setFlushMode(FlushModeType.COMMIT);
}
return EM;
}
And also changed my persistence.xml
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
Now no more warnings.

How to create a JNDI using Eclipse and Tomcat for a Dynamic Web Project without web.xml

I would like to know how to create a JNDI entry for a MySQL database using Eclipse Kepler and Tomcat 7 (Is there a plugin for Eclipse?).
When I created the Dynamic Web Project using Eclipse, I did NOT checked the "Generate web.xml deployment descriptor", so, I do not have a web.xml file in my project.
The JDNI resource definition is declared in Tomcat's <Context> element in context.xml 1, not your new application's web.xml. So whether it's generated or not, it doesn't actually matter.
<Context>
<Resource name="jdbc/YourDB" auth="Container"
type="javax.sql.DataSource"
username="username" password="password"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://dbserver:dbport/actualDbname"/>
</Context>
If you had web.xml in your application, you will need an entry like this to refer to the datasource mentioned above:
<resource-ref>
<res-ref-name>jdbc/YourDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
Since you opted not to have web.xml, you can use annotations:
#Resource(lookup = "java:comp/env/jdbc/YourDB")
private DataSource dataSource;
1 There are multiple ways to define the Context, refer to Tomcat's definition on Defining a Context.
When I posted the question, I forgot to say that I'm using Hibernate and to include the files.
The hibernate.cfg.xml is:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE
hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.datasource">java:comp/env/jdbc/ExemplosWeb</property>
<property name="hibernate.connection.username">TheUsername</property>
<property name="hibernate.connection.password">ThePassword</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="hibernate.use_sql_comments">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.hbm2ddl.auto">create-drop</property>
<property name="current_session_context_class">thread</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- One to One Unidirecional -->
<mapping class="relacionamentoHibernate.bean.PaiOneToOneUnidirecional"/>
<mapping class="relacionamentoHibernate.bean.FilhoOneToOneUnidirecional"/>
</session-factory>
There is an Hibernate util class:
package hibernateUtil;
import javax.annotation.Resource;
import org.hibernate.*;
import org.hibernate.cfg.*;
#Resource(lookup="java:comp/env/jdbc/exemplosweb")
#SuppressWarnings("deprecation")
public class HibernateUtil
{
private static final SessionFactory sessionFactory;
static
{
try
{
// Create the SessionFactory from hibernate.cfg.xml
sessionFactory = new Configuration().configure().buildSessionFactory();
}
catch (HibernateException e)
{
// Make sure you log the exception, as it might be swallowed
e.printStackTrace();
throw new ExceptionInInitializerError(e);
}
catch (NoClassDefFoundError e)
{
e.printStackTrace();
throw new NoClassDefFoundError("static HibernateUtil");
}
}
public static SessionFactory getSessionFactory()
{
return sessionFactory;
}
}
and I got this exception:
Fev 26, 2014 7:02:46 PM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
Fev 26, 2014 7:02:46 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.1.4.Final}
Fev 26, 2014 7:02:46 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Fev 26, 2014 7:02:46 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Fev 26, 2014 7:02:46 PM org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
Fev 26, 2014 7:02:46 PM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
Fev 26, 2014 7:02:46 PM org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity
WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
Fev 26, 2014 7:02:46 PM org.hibernate.cfg.Configuration doConfigure
INFO: HHH000041: Configured SessionFactory: null
org.hibernate.service.jndi.JndiException: Unable to lookup JNDI name [java:comp/env/jdbc/ExemplosWeb]
at org.hibernate.service.jndi.internal.JndiServiceImpl.locate(JndiServiceImpl.java:68)
at org.hibernate.service.jdbc.connections.internal.DatasourceConnectionProviderImpl.configure(DatasourceConnectionProviderImpl.java:116)
at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)

Categories

Resources