JPA in java web

Asked

Viewed 55 times

1

I am with a JAVA WEB project and I am having problems with Hibernate. The error is as follows:

Informações:   HCANN000001: Hibernate Commons Annotations {4.0.2.Final}
Informações:   HHH000412: Hibernate Core {4.2.2.Final}
Informações:   HHH000206: hibernate.properties not found
Informações:   HHH000021: Bytecode provider name : javassist
Grave:   Initial SessionFactory creation failed.java.lang.NoClassDefFoundError: org/hibernate/util/DTDEntityResolver
Advertência:   StandardWrapperValve[ServeletLogin]: Servlet.service() for servlet ServeletLogin threw exception
java.lang.NullPointerException
at DAOs.LoginDBDAO.selectUsuario(LoginDBDAO.java:35)
at Controllers.ControllerLogin.validaUsuario(ControllerLogin.java:21)
at Servlets.ServeletLogin.doPost(ServeletLogin.java:42)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:416)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:283)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)....

Looking through Google I didn’t find anything. But I saw people with similar problems And they always put images of the structure of the pages so there goes:

Web pages

inserir a descrição da imagem aqui

Libraries

inserir a descrição da imagem aqui

persistence.xml

<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="test" >
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <dependency>
            <groupId>org.apache.derby</groupId>
            <artifactId>derbyclient</artifactId>
            <version>10.4.2.0</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>tck-utils-api</artifactId>
            <version>0.9.1</version>
        </dependency>

    <class>Entidades.Usuario</class>
    <properties>
        <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver" />
        <property name="javax.persistence.jdbc.url" value="jdbc:derby://localhost:1527/MackEstagios" />
        <property name="javax.persistence.jdbc.user" value="adm" />
        <property name="javax.persistence.jdbc.password" value="adm" />

                    <property name="hibernate.dialect"  value = "org.hibernate.dialect.DerbyDialect"/>

                    <property name="hibernate.hbm2ddl.auto" value = "update"/>
        <property name="hibernate.show_sql"  value = "true"/>
    </properties>
</persistence-unit>

Hibernate.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
    "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
 <hibernate-configuration>
 <session-factory>
    <property name="connection.driver_class">
        org.apache.derby.jdbc.ClientDriver
    </property>
    <property name="connection.url">
        jdbc:derby://localhost:1527/MackEstagios
    </property>
    <property name="connection.username">
        adm
    </property>
    <property name="connection.password">
        adm
    </property>                        
        <property name="dialect">
        org.hibernate.dialect.DerbyDialect
    </property>
</session-factory>

I believe the error is in the configuration of Hibernate and not in its implementation.

Thank you!

  • 1

    java.lang.NullPointerException&#xA;at DAOs.LoginDBDAO.selectUsuario(LoginDBDAO.java:35) Can give us this method?

1 answer

2


Hello,

You have two problems:

  1. Relate the item Grave: Initial SessionFactory creation failed.java.lang.NoClassDefFoundError: org/hibernate/util/DTDEntityResolver
  2. java.lang.NullPointerException at DAOs.LoginDBDAO.selectUsuario(LoginDBDAO.java:35)

Regarding the problem of item 1, see this link with a question similar to yours. However, in this link there is a difference of projects, referenced link design is using a project with archetype Maven.

Regarding the problem of item 2, you are trying to use a method with an object instance null. However, this error may also come from item 1. So I advise checking it first before going ahead in its development.

Here you can see that there is the class that your project is needing, but this library version hibernate-core version 3.6.0.final not being used in its proejto which is the version hibernate-core-4.2.2.Final.jar.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.