Question

Getting ERROR:404 due to the hibernate mapping in the applicationContext.xml. But unable to find the solution for it.

I have a new Type that is image.

Image.java

import java.util.Map;

import org.springframework.web.multipart.MultipartFile;

public class Image
{
    private String image_size;
    private String image_type;
    private MultipartFile image_file;
    private String image_file_url;
    private String image_status;
    <!-- Getters and Setters -->
}

The following is the code in applicationContext.xml

<bean id="imageSessionFactoryBean" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSourceBean"></property>
    <property name="mappingResources">
        <value>xxx/xxx/xxx/bean/Image.hbm.xml</value>
    </property>
<property name="hibernateProperties">
    <props>
        <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
        <prop key="hibernate.show_sql">true</prop>
    </props>
</property>
</bean>

<bean id="imageHibernateTemplateBean" class="org.springframework.orm.hibernate3.HibernateTemplate">
    <property name="sessionFactory" ref="imageSessionFactoryBean"></property>
</bean>

By only changing the value attribute in the mappingResources property of bean imageSessionFactoryBean I get to see the application working otherwise it shows ERROR:404. I think the reason can be the name of the File(Image.java) but I'm not sure about this. Also the Image.hbm.xml contains the mapping of the class Image.java to the database table image.

Image.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Nov 8, 2012 9:26:27 PM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
    <class name="xxx.xxx.xxx.bean.Image" table="image">
        <id name="img_id" type="java.lang.String">
        <column name="IMG_ID" />
        <generator class="native" />
    </id>
    <property name="content_uid" type="java.lang.String">
        <column name="CONTENT_UID" />
    </property>
    <property name="img_url" type="java.lang.String">
        <column name="IMG_URL" />
    </property>
    <property name="image_type_id" type="java.lang.String">
        <column name="IMAGE_TYPE_ID" />
    </property>
    <property name="image_size_id" type="java.lang.String">
        <column name="IMAGE_SIZE_ID" />
    </property>
    <property name="status" type="java.lang.String">
        <column name="STATUS" />
    </property>
    </class>
</hibernate-mapping>
Was it helpful?

Solution

I assume that you want to make class Image an Hibernate Entity in order to store it in the database.

This will not work, because of its field private MultipartFile image_file;. I highly doubt that you can store this field with hibernate. So instead of having this filed, replace it with an byte array. And Populate this byte array with the content of the Multipart file.

public class Image
{
    //some primary key required.
    private int id;        

    private String image_size;
    private String image_type;
    private byte[] image_content;
    private String image_file_url;
    private String image_status;
    // Getters and Setters

    //Constructor without parameter required.
    public Image() {}        

    public void applyImgContent(MultipartFile upload) {
         this.image_conten = upload.getBytes();
    }

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top