ashweta
ashweta

Reputation: 1487

hibernate hbm2hbmxml

I am trying to use ant hibernatetool task to generate hbm.xml files from my db schema in mysql. ant task runs without errors but no hbm.xml files are generated. What am I missing...

Here are the relevant coonfigurations:

build.xml

<taskdef name="hibernatetool"
    classname="org.hibernate.tool.ant.HibernateToolTask"
    classpathref="3p-classpath">
</taskdef>

<target name="hbmxmlgen"
    description="Creating hbm xml files from DB">
    <hibernatetool>
        <jdbcconfiguration 
            configurationfile="src/config/hibernate.cfg.xml"
            revengfile="src/config/hibernate.reveng.xml"
            detectmanytomany="true">
        </jdbcconfiguration>
        <hbm2hbmxml destdir="${mappings.dir}"/>
    </hibernatetool>
</target>

src/config/hibernate.cfg.xml

<?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="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.url">jdbc:mysql://localhost/?useUnicode=true&characterEncoding=utf8</property>
        <property name="connection.username">root</property>
        <property name="connection.pool_size">1</property>
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="current_session_context_class">thread</property>
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
        <property name="show_sql">true</property>
    </session-factory> </hibernate-configuration>

src/config/reveng.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering SYSTEM "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd">

<hibernate-reverse-engineering>
    <schema-selection match-schema="optimizer_config"/>
    <type-mapping>
        <sql-type jdbc-type="VARCHAR" hibernate-type="string"/>
        <sql-type jdbc-type="NUMERIC" hibernate-type="java.lang.Long" />
        <sql-type jdbc-type="INTEGER" hibernate-type="java.lang.Integer" />
        <sql-type jdbc-type="DECIMAL" hibernate-type="java.lang.Double" />
    </type-mapping>
    <table-filter match-name="*" package="com.sokrati.optimizer.dbaccess.optimizerConfig"/>
</hibernate-reverse-engineering>

Upvotes: 3

Views: 3394

Answers (5)

Nav
Nav

Reputation: 1

Trivial issue. Was going through similar issue. Weird I had to specify exclude="false" for table filter and worked for me

Upvotes: 0

lucentmind
lucentmind

Reputation: 192

can you make sure of following two points.

  1. keep proper version of mysql driver jar in claaspath. (for eg. if you are using mysql 5.x then you need corresponding version of mysql driver jar. Sometimes with old version jar you will not face errors but it will not work as expected)

  2. If possible try to modify property like:

    <property name="connection.url">jdbc:mysql://localhost:3306/?useUnicode=true&characterEncoding=utf8</property>

Upvotes: 0

jason
jason

Reputation: 425

I had the same issue and found the following 2 points useful :

  1. The regular expression to use for match-name if you want all tables is '.*' e.g. <table-filter match-name=".*" package="com.sokrati.optimizer.dbaccess.optimizerConfig"/>

  2. Be aware that schema names are case sensitive, so make sure that the case is correct in your <schema-selection> tag in reveng.xml.

Upvotes: 2

Prasad
Prasad

Reputation:

Try this

<property name="connection.username">ROOT</property>

Upvotes: 0

lud0h
lud0h

Reputation: 2390

I think the table-filter is wrong.

Try:

<table-filter match-name="%" package="com.sokrati.optimizer.dbaccess.optimizerConfig"/>

Upvotes: 1

Related Questions