我正在尝试将对象 Ficheiro 存储在我的内存数据库中。该对象包含:
private int version;
private Workbook content;
这是我用来存储在数据库中的代码:
HSQLServerUtil.getInstance().start("DBMemoria");
Ficheiro fich = new Ficheiro();
fich.setVersion(1);
fich.setContent(workbook);
byte[] by = serialize(fich);
try {
Blob blob = new SerialBlob(by);
Session ss = HibernateUtils.newSessionFactory("csheets\\ext\\Hibernate\\hibernate.cfg.xml").openSession();
ss.beginTransaction();
ss.getTransaction();
ss.save(workbook);
ss.getTransaction().commit();
ss.close();
} catch (SQLException ex) {
System.out.println("ERROR");
}
这是我的 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>
<property name="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property>
<property name="hibernate.hbm2ddl.auto">create</property>
<property name="hibernate.connection.url">jdbc:hsqldb:file:C:\Users\Adam\Documents\NetBeansProjects\lapr4_2dd_g1_s2\lib\Version</property>
<property name="hibernate.connection.username"/>
<property name="hibernate.connection.password"/>
<mapping resource="csheets/ext/Hibernate/File.hbm.xml"/>
</session-factory>
</hibernate-configuration>
最后这是我的 File.hbm.xml 文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class dynamic-insert="false" dynamic-update="false" mutable="true" name="csheets.ext.Hibernate.Ficheiro" optimistic-lock="version" polymorphism="implicit" select-before-update="false" table="File">
<id column="version" name="version" type="int" unsaved-value="0">
<generator class="identity">
</generator>
</id>
<property column="content" name="content" type="blob"/>
<!--<property column="name" name="name" type="string"/>-->
</class>
</hibernate-mapping>
我收到以下错误:
Exception in thread "AWT-EventQueue-0" org.hibernate.MappingException: Unknown entity: csheets.core.Workbook
我已经@Entity
在 Workbook 类中添加了一个。有谁知道怎么了?如果可能的话,你能告诉我我这样做是否正确吗?
谢谢