【问题标题】:JPA Hibernate MappingException: Unknown entityJPA Hibernate MappingException:未知实体
【发布时间】:2012-04-30 08:34:44
【问题描述】:

我创建了一个使用 JPA 和 Hibernate 的简单 CRUD 应用程序。

我有实体注释 JPA javax.persistence.@entity 注释和休眠配置文件 (hibernate.cfg.xml)

我不使用 JPA 实体管理器,而是使用 Hibernate Native API (Session, Session Factory, HibernateUtil)。 我没有休眠映射文件和persistence.xml

任何问题。

请帮忙。

【问题讨论】:

  • 为您的映射注释指定表名 - 看看它是否有效。
  • 我有 @Table(name = "TableName") 并且映射异常仍在引发。
  • 我使用 Hibernate Native API 并且没有自动发现实体类。因此,我只是在 hibermate.cfg.xml 中指定了映射,效果很好。

标签: hibernate jpa mapping


【解决方案1】:

您不需要映射文件,因为您使用的是 JPA 注释。但当然,除非您使用 Spring 3.1 LocalContainerEntityManagerFactoryBean 类,否则您必须拥有 persistence.xml。

【讨论】:

  • 我应该创建 persistence.xml 并包含我使用的提供程序。请给我persistence.xml的例子
  • 我已经创建了persistence.xml,但仍然得到mappingException。
  • 我想使用 JPA 进行映射并使用 Hibernate 作为提供程序。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-09-21
相关资源
最近更新 更多