Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/351.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Hibernate:找不到查询类的持久类:从实体中选择p。演示文稿p_Java_Hibernate_Jpa_Hibernate Mapping - Fatal编程技术网

Java Hibernate:找不到查询类的持久类:从实体中选择p。演示文稿p

Java Hibernate:找不到查询类的持久类:从实体中选择p。演示文稿p,java,hibernate,jpa,hibernate-mapping,Java,Hibernate,Jpa,Hibernate Mapping,我试图坚持我的类,但它总是抛出我这个错误 这是我的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.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>
错误消息的堆栈跟踪:

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.ClobType@38701425
367 [AWT-EventQueue-0] INFO org.hibernate.type.BasicTypeRegistry - Type registration [java.sql.Clob] overrides previous : org.hibernate.type.ClobType@38701425
367 [AWT-EventQueue-0] INFO org.hibernate.type.BasicTypeRegistry - Type registration [wrapper_characters_clob] overrides previous : org.hibernate.type.CharacterArrayClobType@463aa615
367 [AWT-EventQueue-0] INFO org.hibernate.type.BasicTypeRegistry - Type registration [materialized_clob] overrides previous : org.hibernate.type.MaterializedClobType@346dd0b8
367 [AWT-EventQueue-0] INFO org.hibernate.type.BasicTypeRegistry - Type registration [characters_clob] overrides previous : org.hibernate.type.PrimitiveCharacterArrayClobType@15a1faec
367 [AWT-EventQueue-0] INFO org.hibernate.type.BasicTypeRegistry - Type registration [blob] overrides previous : org.hibernate.type.BlobType@3d60a70c
367 [AWT-EventQueue-0] INFO org.hibernate.type.BasicTypeRegistry - Type registration [java.sql.Blob] overrides previous : org.hibernate.type.BlobType@3d60a70c
367 [AWT-EventQueue-0] INFO org.hibernate.type.BasicTypeRegistry - Type registration [materialized_blob] overrides previous : org.hibernate.type.MaterializedBlobType@1477244f
367 [AWT-EventQueue-0] INFO org.hibernate.type.BasicTypeRegistry - Type registration [wrapper_materialized_blob] overrides previous : org.hibernate.type.WrappedMaterializedBlobType@19f0c908
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
我一直在寻找一些方法来解决这个问题,但我不习惯使用hibernate,并且我遵循了他们关于映射的文档文章,但它似乎不起作用。

如文档所述,例如,实体的名称默认为简单的类名。它不包含包的名称。在这种情况下,实体的名称是
Presentation

类中的方法也返回包,所以在这种情况下它没有用处。更好ḿ这种情况的方法是:

作为旁注,可能没有理由使用org.hibernate.annotations.Entity而不是javax.persistence.Entity。

例如,如文档所述,实体的名称默认为简单类名。它不包含包的名称。在这种情况下,实体的名称是
Presentation

类中的方法也返回包,所以在这种情况下它没有用处。更好ḿ这种情况的方法是:


作为补充说明,可能没有理由使用org.hibernate.annotations.Entity而不是javax.persistence.Entity。

粘贴异常的准确完整堆栈跟踪。请注意,这样的查询返回的是
列表
,而不是
列表
。请注意,这样的查询返回的是
列表
,而不是
列表
。我添加了堆栈跟踪,将其更改为List,但结果保持不变。实际上,您的旁注是问题的真实答案:类不是实体,因为它没有用javax.persistence.entity注释。使用完全限定的名称不是强制性的,但它是允许的,并且工作良好。这确实解决了它:)感谢您的帮助和解释information@JBNizet请你再加一点硼酸好吗?“它不是用javax.persistence.Entity注释的”是什么意思?这是否意味着他应该像
@Entity(name=“full.package.name.with.class.name”)
这样做,以便能够使用
class.getName()
?@Pere否,我的意思是OP使用了注释org.hibernate.annotations.Entity,而不是javax.persistence.Entity,这就是他犯错误并提出这个问题的真正原因。这不仅仅是旁注。这是答案中最重要的部分。实际上,你的旁注是问题的真正答案:类不是实体,因为它没有用javax.persistence.entity注释。使用完全限定的名称不是强制性的,但它是允许的,并且工作良好。这确实解决了它:)感谢您的帮助和解释information@JBNizet请你再加一点硼酸好吗?“它不是用javax.persistence.Entity注释的”是什么意思?这是否意味着他应该像
@Entity(name=“full.package.name.with.class.name”)
这样做,以便能够使用
class.getName()
?@Pere否,我的意思是OP使用了注释org.hibernate.annotations.Entity,而不是javax.persistence.Entity,这就是他犯错误并提出这个问题的真正原因。这不仅仅是旁注。这是答案中最重要的部分。
Query q = session.createQuery("SELECT p FROM " + Presentation.class.getName() + " p");
presentationModel = new PresentationTableModel((List<Object[]>)q.list());
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
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.ClobType@38701425
367 [AWT-EventQueue-0] INFO org.hibernate.type.BasicTypeRegistry - Type registration [java.sql.Clob] overrides previous : org.hibernate.type.ClobType@38701425
367 [AWT-EventQueue-0] INFO org.hibernate.type.BasicTypeRegistry - Type registration [wrapper_characters_clob] overrides previous : org.hibernate.type.CharacterArrayClobType@463aa615
367 [AWT-EventQueue-0] INFO org.hibernate.type.BasicTypeRegistry - Type registration [materialized_clob] overrides previous : org.hibernate.type.MaterializedClobType@346dd0b8
367 [AWT-EventQueue-0] INFO org.hibernate.type.BasicTypeRegistry - Type registration [characters_clob] overrides previous : org.hibernate.type.PrimitiveCharacterArrayClobType@15a1faec
367 [AWT-EventQueue-0] INFO org.hibernate.type.BasicTypeRegistry - Type registration [blob] overrides previous : org.hibernate.type.BlobType@3d60a70c
367 [AWT-EventQueue-0] INFO org.hibernate.type.BasicTypeRegistry - Type registration [java.sql.Blob] overrides previous : org.hibernate.type.BlobType@3d60a70c
367 [AWT-EventQueue-0] INFO org.hibernate.type.BasicTypeRegistry - Type registration [materialized_blob] overrides previous : org.hibernate.type.MaterializedBlobType@1477244f
367 [AWT-EventQueue-0] INFO org.hibernate.type.BasicTypeRegistry - Type registration [wrapper_materialized_blob] overrides previous : org.hibernate.type.WrappedMaterializedBlobType@19f0c908
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
session.createQuery("SELECT p FROM " + Presentation.class.getSimpleName() + " p");