0

オブジェクト 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

私はすでに@EntityWorkbook クラスに入れています。誰が何が悪いのか知っていますか?可能であれば、私がこれを正しく行っているかどうか教えていただけますか?

ありがとう

4

1 に答える 1