Search code examples
javahibernatejakarta-eehibernate-mappingpojo

org.hibernate.InvalidMappingException: Could not parse mapping document from resource hibernate.hbm.xml. Why am I getting it?


While trying to write a text file to the database, I get the following exception :

org.hibernate.InvalidMappingException: Could not parse mapping document 
from resource hibernate.hbm.xml

as soon as I click the html submit button :

<form method="post" enctype="multipart/form-data" action="FileHandler">
        <input type="file" name="file" /> <br />
        <input type="submit" value="submit" />
</form>

I don't know the reason for why am I getting it. Following is the hibernate mapping file :

    <hibernate-mapping>
      <class name="pojo.File" table="b_files"/>
        <id name="serial_number">
      <generator class="increment" />
        </id>
        <property name="file" />
    </hibernate-mapping>

Following is the class inside the pojo package (The mapping class) :

package pojo;

public class File {
    private byte file[] = new byte[5120];
    private int serial_number;

    public int getSerial_number() {
        return serial_number;
    }

    public void setSerial_number(int serial_number) {
        this.serial_number = serial_number;
    }

    public byte[] getFile() {
        return file;
    }

    public void setFile(byte[] file) {
        this.file = file;
    }

}

I used the this command to make a table named b_files :

create table b_files(files_uploaded mediumblob, serial_number integer);

Note : What I guess, is a problem with a property named 'file' in the mapping file. Is that Okay ? Because I do not get 'file' as a hint in my netbeans IDE. So I guess that it may the problem.


Solution

  • You are closing class in the wrong place. id and the property should precede a </class>, not close class with shortcut in its original line.