1

well i need almost the same thing as in this question How do you translate Hibernate class mappings to a Spring application context?

but i shouldn't use annotations, i need to save xml mapping, so how should i specify mappings in spring config?

P. S. sorry for possible duplicate, but i have seen only annotation-based suggestions

my current configuration with annotations : hibernate.cfg.xml

<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
        <property name="hibernate.connection.url">jdbc:oracle:thin:@127.0.0.1:1521/XE</property>
        <property name="hibernate.connection.username">username</property>
        <property name="hibernate.connection.password">pass</property>
        <property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>

        <property name="show_sql">true</property>
        <mapping class="com.foo.domain.News"></mapping>
    </session-factory>
</hibernate-configuration>

applicationContext.xml sessionFactory bean:

<bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="configLocation">
            <value>/WEB-INF/hibernate.cfg.xml</value>
        </property>

        <property name="configurationClass">
            <value>org.hibernate.cfg.AnnotationConfiguration</value>
        </property>


        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.dialect">${DIALECT}</prop>
                <prop key="hibernate.connection.charSet">UTF-8</prop>

            </props>
        </property>
    </bean>

2 Answers 2

2

The hibernate documentation is quite good.

Here you have some simple examples to start with: Hibernate documentation

You have to create you mapping xml like:

Person.hbm.xml  (which maps Person.java)

<class name="Person" table="PERSON">
    <id name="id" column="PERSON_ID">
        <generator class="native"/>
    </id>
    <property name="age"/>
    <property name="firstname"/>
    <property name="lastname"/>
</class>

Then add this file to your hibernate configuration

<mapping resource="Person.hbm.xml"/>
Sign up to request clarification or add additional context in comments.

Comments

1

Set the mappingLocations property on your LocalSessionFactoryBean:

<property name="mappingLocations">
    <list>
        <value>classpath:/path/to/mapping.hbm.xml</value>
        ...
    </list>
</property>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.