- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
因此,在处理我的项目时,我最初在 java 类中使用了 Hibernate Annotations @Entity、@Table、@Column、@SequenceGenerator 和 @GenerateValue,并且能够成功将项目添加到我的 Oracle 数据库中。
现在我尝试复制相同的内容,但使用 *.hbm.xml 文件并遇到问题。
以下是原始 Java 类代码,注释已被注释掉:
//@Entity
//@Table (name="client")
@SequenceGenerator(name="seq_client",sequenceName="BIMB2013WMMEE.seq_client",
allocationSize=1, initialValue=1)
public class Client {
//Fields
//@Id
//@GeneratedValue(strategy=GenerationType.SEQUENCE)
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seq_client")
//@Column(name="CLIENT_ID")
private int id;
//@Column(name="CLIENT_NAME")
private String clientName;
//@Column(name="CLIENT_CODE")
private String clientCode;
这是相应的 hbm.xml 文件,位于我的项目的 src 目录中。
<hibernate-configuration>
<session-factory>
<!-- JDBC Database connection settings -->
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="connection.url">jdbc:oracle:thin:@endeavour.us.manh.com:1523/pso11r2f</property>
<property name="connection.username">BIMB2013WMMEE</property>
<property name="connection.password">BIMB2013WMMEE</property>
<!-- JDBC connection pool settings ... using built-in test pool -->
<property name="connection.pool_size">1</property>
<!-- Select our SQL dialect -->
<property name="dialect">org.hibernate.dialect.Oracle10gDialect</property>
<!-- Echo the SQL to stdout -->
<property name="show_sql">true</property>
<!-- Set the current session context -->
<property name="current_session_context_class">thread</property>
</session-factory>
</hibernate-configuration>
最后是 Eclipse 错误代码:
Exception in thread "main" org.hibernate.MappingException: Unknown entity: com.luv2code.hibernate.demo.entity.Client
我没有对实际创建对象并通过 session 将其添加到数据库的类进行任何更改...我需要这样做吗?
感谢您的帮助!!
最佳答案
您显示的 xml 文件是 hibernate 配置文件,而不是 hbm.xml 文件。您必须为您创建的每个持久实体创建“classname.hbm.xml”文件 - 在您的情况下它是您的 Client 类。所以你必须制作一个 Client.hbm.xml 文件。之后,您必须将该资源添加到您的配置文件和 Hibernate Utility 文件中。您可能会发现这很有帮助。 http://www.mkyong.com/hibernate/how-to-add-hibernate-xml-mapping-file-hbm-xml-programmatically/
关于java - 从 Hibernate Annotations 切换到 hbm.xml 文件时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37661588/
我使用 hibernate 作为 ORM 工具,我面临一个问题, 我需要将全局临时表映射到 HBM。现在,问题在于键,我知道在 hbm 中必须有一些关键字段,但是我应该输入什么,因为任何列在任何时间点
Hibernate 的常用配置文件主要分为 2 种:核心配置文件(hibernate.cfg.xml)和映射文件(Xxx.hbm.xml),它们主要用于配置数据库连接、事务管理、Hibernate 本
在我的 MSSQL 服务器中,我有一个名为 AllFavourite 的 SQL View 。为了将数据加载到我的 DTO 类中,我的 hbm.xml 文件中有以下内容... 在我的代码中
我有以下三个类: public class Student { private Integer studentId; private StudentSchool studentScho
我正在从 NHibernate 映射创建我的表和索引。 例如,我按如下方式创建姓氏索引: 我想创建一个复杂的索引,以便例如 LastName 和 FirstName 作为一个索引生成。这在 NH
我在映射我们的 byte[] 时遇到问题 field 。我一直在寻找几种解决方案,但到目前为止都没有奏效。我得到的只是这个异常(exception): The length of the byte[]
我正在通过代码使用 NHibernate 映射,并以这种方式创建 session 工厂: var mapper = new ModelMapper(); map
我的 hibernate hbm xml 有一个属性映射为 我正在使
我在屏幕上显示位图时遇到问题。当我编译并运行不显示任何内容时,尝试逐步调试,发现下面的代码是问题所在。 HBITMAP hbm = (HBITMAP)LoadImage(hInstance,
我是 hibernte 新手。我正在尝试使用 hibernate 从 oracle 表中简单检索记录。 我的实体类名为pojo1,pojo1.hbm.xml如下: 我在运行包含所有
例如, 如果我想要f
我正在通过代码使用 NHibernate 映射,并以这种方式创建 session 工厂: var mapper = new ModelMapper(); map
我有一个有两个主键的表,我如何在 hbm 映射文件中映射相同的表。如何定义两个主键。 最佳答案 两个主键?您可能指的是复合主键。检查this here . 关于java - 如何在 hbm 中定义
我是 hibernate 新手,遇到了一个问题。我已经阅读了 hibernate 网站上的入门指南等所有内容,但仍然无法找到解决方案。 我有一堂这样的课: public class ResultTre
我在打开 hbm 文件时遇到这个奇怪的问题。我正在使用 hibernate3.jar。我还验证了类路径中只有一个 hibernate3.jar 并且它包含 hibernate 映射 dtd 文件。 我
你能否让 1 个表被映射到 2 个不同类的 2 个不同的 HBM 引用(它们是不相关的,基本类,没有继承)。 我知道由于重复,这可能是不好的做法,但它与代码维护有关。我试图避免删除其中一个类。 谢谢,
例如, 如果我想要f
我正在开发一个 Spring 框架和 hibernate 应用程序,其中包含一个企业 Web 应用程序的中央数据库,该应用程序具有每天约有 1000 位用户在线。 您可以假设有一个计费应用程序,任何人
我是 Hibernate 新手,正在尝试插入 ArrayList在数据库中使用 .hbm 映射文件。我不想使用任何注释。我搜索了如何插入 ArrayList并从 here 找到工作代码。 我期待一个包
我在谷歌上搜索了很多,并且遵循了很多关于它的教程,但我没有让它工作。我在表 Player 和 Type 之间有多对多关系。两个表都通过 typeperplayer 连接。在表中 typeperplay
我是一名优秀的程序员,十分优秀!