Hello Hibernates,
after the fast and very competent help I got here I must expand my little
academic example, because I'm reaching against my limits.
I add another schema:
Code:
CREATE DATABASE `test_expanded` /*!40100 DEFAULT CHARACTER SET latin1 */;
The new schema contains the following table:Code:
CREATE TABLE `test_expanded`.`father` (
`FATHER_ID` int(10) unsigned NOT NULL auto_increment,
PRIMARY KEY USING BTREE (`FATHER_ID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC;
The before mentioned Hibernate Tool tutorial says with respect to schema reverse
engineering:
5.2.1. Schema Selection (<schema-selection>)[url]
http://www.hibernate.org/hib_docs/tools ... ering.html[/url]
Quote:
By default the reverse engineering will read all schemas and then use
<table-filter> to decide which tables get reverse engineered and which do not;
this makes it easy to get started but can be inefficient on databases with many
schemas.
Because of this I expected that the reverse engineering will include the new
schema and the new table and will create the Father.java and the Father.hbm.xml
files. But unfortunately it isn't so.
Therefore I expand my
hibernate.reveng.xml file so it looks like this:
Code:
<hibernate-reverse-engineering>
<schema-selection match-catalog="test" match-schema="test" />
<schema-selection match-catalog="test_expanded" match-schema="test_expanded" match-table="father" />
<table name="father"
catalog="test_expanded"
schema="test_expanded">
<primary-key>
<key-column name="FATHER_ID" />
</primary-key>
</table>
<table name="child">
<foreign-key constraint-name="MOTHER" foreign-table="mother">
<column-ref local-column="MOTHER" foreign-column="MOTHER_ID"/>
<many-to-one property="mother"/>
</foreign-key>
<foreign-key constraint-name="FATHER" foreign-catalog="test_expanded" foreign-schema="test_expanded" foreign-table="father">
<column-ref local-column="FATHER" foreign-column="FATHER_ID" />
<many-to-one property="father" />
</foreign-key>
</table>
</hibernate-reverse-engineering>
As you can see I tried the
<schema-selection> from section
5.2.1. Schema Selection (<schema-selection>)and the specific table configuration
<table> from section
5.2.4. Specific table configuration (<table>).
My expectations are:Hibernate creates the Father.java and the Father.hbm.xml files.
The reality is:No Father.java and no Father.hbm.xml files.
The Child.hbm.xml file is expanded by some lines.
Code:
<hibernate-mapping>
<class name="Child" table="child">
<id name="childId" type="java.lang.Integer">
<column name="CHILD_ID" />
<generator class="identity" />
</id>
<many-to-one name="mother" class="Mother" fetch="select">
<column name="MOTHER" />
</many-to-one>
<property name="father" type="java.lang.Integer">
<column name="FATHER" />
</property>
</class>
</hibernate-mapping>
But instead of
Code:
<property name="father" type="java.lang.Integer">
<column name="FATHER" />
</property>
I expected something like this:
Code:
<many-to-one name="father" class="Father" fetch="select">
<column name="FATHER" />
</many-to-one>
My first idea is that the
hibernate.default_schema and the
hibernate.default_catalog lines in my
hibernate.cfg.xml file are
more then default values.
Code:
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306</property>
<property name="hibernate.connection.username">test</property>
<property name="hibernate.connection.password">test</property>
<property name="hibernate.default_schema">test</property>
<property name="hibernate.default_catalog">test</property>
<!-- SQL dialect -->
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
</session-factory>
</hibernate-configuration>
But when I remove
<property name="hibernate.default_catalog">test</property>
I'm at the starting point of this thread and when I remove
<property name="hibernate.default_schema">test</property>
I get the following error prompt:
BUILD FAILED
D:\Arbeitsbereich\eclipse-
workspace\HibernateMotherChildTest\src\reveng\build.reveng.xml:28:
org.hibernate.exception.GenericJDBCException: Could not get list of suggested
identity strategies from database. Probably a JDBC driver problem.
Thanks to all folks who read my long post 'til here and special thanks in
advance to all of those who try to solve my problem.
Arnim