One correction to my post above: the java class is annotated with the right table name AND catalog name.
E.g. @Table(name = "user", catalog = "maintenance")
So that's good, if I would have tables from multiple schemas, there should be no confusion where the class is mapped to.
Question remains how I can reverse engineer from multiple schemas / catalogs from MySQL.
1 of 1 people found this helpful
hibernate tools were actually built from day 1 to support multiple schemas and catalogs so unless you are doing something unexpected or we got a new bug then it should "just work".
btw. As far as I recall mysql doesn't actually really have schemas or at least it doesn't report them as such in jdbc metadata.
Could you please show your config and properties that you use ? (btw. datasource is irrelevant since hibernate tools doesn't use that since we are not running inside the appserver)
Here is DTP issue for reference https://bugs.eclipse.org/bugs/show_bug.cgi?id=249013 MySQL: catalogs and schemas inconsistent with other vendorsit it says in first paragraph of description:
Using MySQL 5.0.41, Database.getCatalogs() returns an empty list; while
Database.getSchemas() returns a list with a single Schema that has the same
name as the Database. This Schema contains the Database's Tables.
Thanks to the replies from Denis and Max, I tried a few more things and got it to work now.The issue was with the hibernate.reveng.xml file.Based on what the wizard created, I had just this in in the reveng.xml file:<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" ><hibernate-reverse-engineering><table-filter match-schema="maintenance" match-name=".*"/><table-filter match-schema="consultant_db" match-name=".*"/></hibernate-reverse-engineering>I also changed the 'match-schema' attribute to 'match-catalog', but that didn't help.However, when I changed it to the following, it worked fine:<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" ><hibernate-reverse-engineering><schema-selection match-catalog="maintenance" /><schema-selection match-catalog="consultant_db" /></hibernate-reverse-engineering>In other words, just using 'table-filter' doesn't make it look at different catalogs/ databases in MySQL, but the 'schema-selection' element does.I think this is quite acceptable for how it works.However, the Hibernate reverse engineering editor can perhaps be improved:- How can we get multiple schemas to show up in the wizard? It looks like the wizard looks at the hibernate.connection.url property in the hibernate-console.properties file. However, when I leave out the name of the database (e.g. jdbc:mysql://localhost:3306) without the database, the wizard does not return any tables.- The wizard could have an extra tab at the bottom where you can select the schemas/ catalogs you want, effectively creating the <schema-selection ...> tagsThank you!
as written in my last post:
use <schema-selection ..> in the reveng.xml file.
the issue is most likely affected by how mysql views schema and catalog based on your jdbc url and then return it to the jdbc metadata.
feel free to add jira for the various enhancements you suggested.