Hibernate Tools: Mappings and Annotations Fail
-
07-07-2021 - |
質問
This is driving me crazy -- I'm pretty sure that Hibernate can determine mapping relationships between tables and thus reflect this in the POJO's generated.
Except it's not.
I am using MySQL with STS & Hibernate Tools 4.0.0 and I have a one-to-many and a one-to-one table relationship, between Person <--> Phone and Phone <--> PhoneType and I am able to generate using the 'Hibernate Code Generation Configuration' the 'Domain Code' and the 'DAO Code', however neither of the files have any mappings between the tables.
Now here is a possible issue:
In order to get any annotations at all, I have switched on the option 'Generate EJB3 annotations'. Now I am using plain old Hibernate here, and not JPA.
So my questions are:
- Can Hibernate Tools generate Annotations for plain old Hibernate?
- Can it generate mapping information in the POJO's (i.e. @manytomany / @manytoone) ?
Thanks a lot for your help,
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!
他のヒント
Worked:
I created new reverse engineering XML "hibernateII.reveng.xml" from Hibernate tool plugin in STS eclipse, and it resolved the problem.
Though i had also tried changing content of existing file, but that did not work out and content of old and new files were same, weird, but new file solved the issue.