In the hibernate.cfg.xml file, can you use both the mapping resource and the mapping class in the same factory session?

I am creating a system that does the basic job of storing hjernate POJO in a database. We have a slightly outdated system in place at the moment when the old 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 normal only when the time comes for unit testing, and it seems that having both a resource and class mappings in the cfg.xml file seems to interrupt unit tests during build.

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

Is there any way around this? Can I use 2 different display types in hibernate.cfg.xml?

+4
source share

Source: https://habr.com/ru/post/1480082/


All Articles