4

I'm making putting together a system that does the basic job of persisting hibernate POJOs into a database. We've got a bit of a legacy system in place at the moment where the older POJOs are generated by hbm.xml files, but the new POJOs are just annotated classes.

this is my hibernate.cfg.xml file

<?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 name="">
        <!-- Database connection settings HSQL DB -->
        <property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
        <property name="connection.url">jdbc:hsqldb:mem:test</property>
        <property name="connection.username">sa</property>
        <property name="connection.password" />
        <property name="dialect">org.hibernate.dialect.HSQLDialect</property>
        <property name="hbm2ddl.auto">create-drop</property>
        <property name="show_sql">true</property>
        <property name="show_comments">true</property>
        <property name="hibernate.connection.pool_size">0</property>
        <mapping resource="com/dto/Address.hbm.xml" />
        <mapping class="com.dto.Customer"/>
    </session-factory>
</hibernate-configuration>

This is ok except when it comes time to Unit testing and it appears that having both a resource and a class mapping in the cfg.xml file seems to break unit tests at build time.

    <mapping resource="com/dto/Address.hbm.xml" />
    <mapping class="com.dto.Customer"/>

Is there a way round this? Can I even use the 2 differnt mapping types in a hibernate.cfg.xml file?

2
  • 1
    According to the Hibernate documentation, you can mix annotated persistent classes and classic hbm.cfg.xml declarations with the same SessionFactory. You can however not declare a class several times (whether annotated or through hbm.xml). You cannot mix configuration strategies (hbm vs annotations) in an entity hierarchy either. May 10, 2013 at 9:41
  • Ah well... I'll just have to convert the classes generated by the hbm.xml files into annotated classes(my preferred way of doing things hibernate-wise). Thank you for your help!
    – Jimbob
    May 10, 2013 at 9:47

0

Your Answer

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

Browse other questions tagged or ask your own question.