質問

I am using Hibernate Tools to reverse engineer from a MySQL 5.5.27 using STS 2.9.2 and Hibernate Tools 4.0.0.

It generates the POJO classes correctly, but is NOT picking up on the foreign key relationships defined across the tables (i.e. no sets nor relationships created at all!).

Any idea from your experience whether this tool works with MySQL or what I am doing wrong?

Thanks,

Bob

役に立ちましたか?

解決

OK, I got it work at last!

The problem was, as with all things of a technical nature both simple and profound.

In a word: CaseSensitive

I had created my tables with capitaliZatioN (i.e. Person, Phone) and I used the MySQL Workbench to create the foreign keys and they looked like this:

CONSTRAINT FK_Phone_Person FOREIGN KEY (person_id) REFERENCES Person (person_id)

instead of

CONSTRAINT FK_Phone_Person FOREIGN KEY (person_id) REFERENCES person (person_id)

Notice the capitalization.

SOO happy after spending a lot of blood, sweat and tears trying to get that damn thing to work when all along the case was the problem!

他のヒント

many times the default engine of mysql also causes this issue i,e if the default engine through which the tables are create is "MyISAM" then please change it to "InnoDB"; the query to change is ALTER TABLE table_name ENGINE = InnoDB;, hope this works :)

My experience is that the reverse engineering tool needs specific constraints to work, if you have @OneToMany relationships they must have an intermediary table with the ids of both tables and the constraint that you cannot have null values nor orphan rows.

Also the tables will need to be named accordingly to your entities and intermediary tables must be named like owning_entity_entity2 to work.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top