Estoy tratando de persistir en mis clases, pero siempre me lanza este error.

Este es mi hibernate.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
  <session-factory>
    <!-- SQL dialect -->
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>

    <!-- Database connection settings -->
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/Projecten2?zeroDateTimeBehavior=convertToNull</property>
    <property name="hibernate.connection.username">MyUser</property>
    <property name="hibernate.connection.password">MyPass</property>
    <property name="hibernate.current_session_context_class">org.hibernate.context.ThreadLocalSessionContext</property>

    <!-- Echo all executed SQL to stdout -->
    <property name="show_sql">false</property>

    <!-- Mappings -->
    <mapping class="entity.Presentation"/>
  </session-factory>
</hibernate-configuration>

Y esta es la clase en la que yo estoy tratando de persistir

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package entity;


import java.util.List;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.eclipse.persistence.jpa.jpql.parser.DateTime;
import org.hibernate.annotations.Entity;

/**
 *
 * @author authorName
 */
@Entity
public class Presentation 
{
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Id
    private int id;
    @Temporal(TemporalType.TIMESTAMP)
    private DateTime beginTime;
    @Temporal(TemporalType.TIMESTAMP)
    private DateTime endTime;

    @ManyToOne
    private Location location;
    private int locationId;

    @ManyToMany
    private List<User> users;

    @ManyToMany(mappedBy = "presentations")
    private List<Planning> plannings;

}

La consulta estoy tratando de ejecutar:

Query q = session.createQuery("SELECT p FROM " + Presentation.class.getName() + " p");
presentationModel = new PresentationTableModel((List<Object[]>)q.list());

Y esto es cómo puedo obtener la sesión para ejecutar consultas

Session session = HibernateUtil.getSessionFactory().getCurrentSession();

stacktrace de la mensaje de error:

56 [AWT-EventQueue-0] INFO org.hibernate.annotations.common.Version - Hibernate Commons Annotations 3.2.0.Final
59 [AWT-EventQueue-0] INFO org.hibernate.cfg.Environment - Hibernate 3.6.10.Final
60 [AWT-EventQueue-0] INFO org.hibernate.cfg.Environment - hibernate.properties not found
61 [AWT-EventQueue-0] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
63 [AWT-EventQueue-0] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
93 [AWT-EventQueue-0] INFO org.hibernate.cfg.Configuration - configuring from resource: /hibernate.cfg.xml
93 [AWT-EventQueue-0] INFO org.hibernate.cfg.Configuration - Configuration resource: /hibernate.cfg.xml
123 [AWT-EventQueue-0] WARN org.hibernate.util.DTDEntityResolver - recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/instead. Refer to Hibernate 3.6 Migration Guide!
141 [AWT-EventQueue-0] INFO org.hibernate.cfg.Configuration - Configured SessionFactory: null
167 [AWT-EventQueue-0] INFO org.hibernate.cfg.Configuration - Hibernate Validator not found: ignoring
169 [AWT-EventQueue-0] INFO org.hibernate.cfg.search.HibernateSearchEventListenerRegister - Unable to find org.hibernate.search.event.FullTextIndexEventListener on the classpath. Hibernate Search is not enabled.
171 [AWT-EventQueue-0] INFO org.hibernate.connection.DriverManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)
171 [AWT-EventQueue-0] INFO org.hibernate.connection.DriverManagerConnectionProvider - Hibernate connection pool size: 20
171 [AWT-EventQueue-0] INFO org.hibernate.connection.DriverManagerConnectionProvider - autocommit mode: false
175 [AWT-EventQueue-0] INFO org.hibernate.connection.DriverManagerConnectionProvider - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3306/Projecten2?zeroDateTimeBehavior=convertToNull
175 [AWT-EventQueue-0] INFO org.hibernate.connection.DriverManagerConnectionProvider - connection properties: {user=root, password=****}
340 [AWT-EventQueue-0] INFO org.hibernate.dialect.Dialect - Using dialect: org.hibernate.dialect.MySQLDialect
346 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - Database ->
name : MySQL
version : 5.6.14
major : 5
minor : 6
347 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - Driver ->
name : MySQL-AB JDBC Driver
version : mysql-connector-java-5.1.23 ( Revision: ${bzr.revision-id} )
major : 5
minor : 1
347 [AWT-EventQueue-0] INFO org.hibernate.transaction.TransactionFactoryFactory - Using default transaction strategy (direct JDBC transactions)
348 [AWT-EventQueue-0] INFO org.hibernate.transaction.TransactionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
348 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - Automatic flush during beforeCompletion(): disabled
348 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - Automatic session close at end of transaction: disabled
348 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - JDBC batch size: 15
348 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - JDBC batch updates for versioned data: disabled
348 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - Scrollable result sets: enabled
348 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - JDBC3 getGeneratedKeys(): enabled
348 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - Connection release mode: auto
348 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - Maximum outer join fetch depth: 2
348 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - Default batch fetch size: 1
348 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - Generate SQL with comments: disabled
348 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - Order SQL updates by primary key: disabled
348 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - Order SQL inserts for batching: disabled
348 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
349 [AWT-EventQueue-0] INFO org.hibernate.hql.ast.ASTQueryTranslatorFactory - Using ASTQueryTranslatorFactory
349 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - Query language substitutions: {}
349 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - JPA-QL strict compliance: disabled
349 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - Second-level cache: enabled
349 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - Query cache: disabled
349 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory
350 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - Optimize cache for minimal puts: disabled
350 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - Structured second-level cache entries: disabled
353 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - Statistics: disabled
353 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - Deleted entity synthetic identifier rollback: disabled
353 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - Default entity-mode: pojo
353 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - Named query checking : enabled
353 [AWT-EventQueue-0] INFO org.hibernate.cfg.SettingsFactory - Check Nullability in Core (should be disabled when Bean Validation is on): enabled
364 [AWT-EventQueue-0] INFO org.hibernate.impl.SessionFactoryImpl - building session factory
367 [AWT-EventQueue-0] INFO org.hibernate.type.BasicTypeRegistry - Type registration [clob] overrides previous : org.hibernate.type.[email protected]
367 [AWT-EventQueue-0] INFO org.hibernate.type.BasicTypeRegistry - Type registration [java.sql.Clob] overrides previous : org.hibernate.type.[email protected]
367 [AWT-EventQueue-0] INFO org.hibernate.type.BasicTypeRegistry - Type registration [wrapper_characters_clob] overrides previous : org.hibernate.type.[email protected]
367 [AWT-EventQueue-0] INFO org.hibernate.type.BasicTypeRegistry - Type registration [materialized_clob] overrides previous : org.hibernate.type.[email protected]
367 [AWT-EventQueue-0] INFO org.hibernate.type.BasicTypeRegistry - Type registration [characters_clob] overrides previous : org.hibernate.type.[email protected]
367 [AWT-EventQueue-0] INFO org.hibernate.type.BasicTypeRegistry - Type registration [blob] overrides previous : org.hibernate.type.[email protected]
367 [AWT-EventQueue-0] INFO org.hibernate.type.BasicTypeRegistry - Type registration [java.sql.Blob] overrides previous : org.hibernate.type.[email protected]
367 [AWT-EventQueue-0] INFO org.hibernate.type.BasicTypeRegistry - Type registration [materialized_blob] overrides previous : org.hibernate.type.[email protected]
367 [AWT-EventQueue-0] INFO org.hibernate.type.BasicTypeRegistry - Type registration [wrapper_materialized_blob] overrides previous : org.hibernate.type.[email protected]
390 [AWT-EventQueue-0] INFO org.hibernate.impl.SessionFactoryObjectFactory - Not binding factory to JNDI, no JNDI name configured
438 [AWT-EventQueue-0] WARN org.hibernate.hql.QuerySplitter - no persistent classes found for query class: SELECT p FROM entity.Presentation p

He estado buscando un poco para arreglar esto, pero no estoy acostumbrado a usar hibernate y he seguido su documentación artículo acerca de la asignación, pero no parece funcionar.

  • Pegue el exacto y completo seguimiento de la pila de la excepción. Tenga en cuenta que una consulta devuelve un List<Presentation>, no List<Object[]>.
  • He añadido el seguimiento de la pila, he cambiado a la Lista de<Presentación> pero el resultado sigue siendo el mismo

1 Comentario

  1. 5

    Tal como se documenta por ejemplo aquí, nombre de la entidad por defecto el simple nombre de la clase. No contiene el nombre del paquete. En este caso el nombre de la entidad es Presentation.

    Método getName en java.lang.Class devuelve también el paquete, por lo que no es útil en este caso. Mejor ḿethod para este caso es getSimpleName():

    session.createQuery("SELECT p FROM " + Presentation.class.getSimpleName() + " p");

    Como una nota de lado, probablemente no hay ninguna razón para utilizar org.hibernate.las anotaciones.Entidad en lugar de javax.la persistencia.Entidad.

    • En realidad, su nota es la verdadera respuesta a la pregunta: la clase no es una entidad, porque no, con la anotación javax.la persistencia.Entidad. El uso del nombre completo no es obligatorio, pero es permitido y funciona bien.
    • Esta solucionado, de hecho 🙂 gracias por la ayuda y el bien explicado información
    • podría usted ellaborate un poco más, por favor? ¿Qué quieres decir con «no, con la anotación javax.la persistencia.La entidad»? Eso no significa que él debe hacer algo como @Entity(name="full.package.name.with.class.name") con el fin de ser capaz de utilizar class.getName()?
    • no, me refiero a que el OP se utiliza la anotación org.hibernate.las anotaciones.Entidad, en lugar de javax.la persistencia.Entidad, y que es la razón real de por qué había un error y le pidió a esta pregunta. No es sólo una nota al margen. Es la parte más importante de la respuesta.

Dejar respuesta

Please enter your comment!
Please enter your name here