Reputation: 18143
Is there any way to use a regular expression (or just *) to tell Hibernate to pick up all of the hbm.xml files in a given directory, or even in the project? I just reverse engineered my database, and don't feel like specifying a hundred plus tables with <mapping resource="...">
I'm using Maven to run hbm2java. Do I need to indicate something in my component configuration?
My hibernate.cfg.xml currently looks like this:
<?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>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@....</property>
<property name="hibernate.connection.username">hithere</property>
<property name="hibernate.connection.password">shhhh</property>
<property name="hibernate.default_schema">foobar</property>
<property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
<mapping resource="com/foo/bar/db/Blip.hbm.xml" />
<mapping resource="com/foo/bar/db/Blap.hbm.xml" />
<mapping resource="com/foo/bar/db/Blop.hbm.xml" />
</session-factory>
</hibernate-configuration>
Upvotes: 0
Views: 5145
Reputation: 90447
I don't think hibernate.cfg.xml
supports regular expression to selectively import resource. You can resort to import the resource pragmatically .Before calling buildSessionFactory() of Configuration to build the SessionFactory , use regular expression to find out a list of the mapping file path that you want to hibernate to pick up , then use addResource() or addClass() to add them to the Configuration object.
Or if you use JPA with hibernate as the implementation, you can enable auto discovery of all hbm.xml files by setting the property hibernate.archive.autodetection
to hbm
(See this)
Upvotes: 1