2

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:

  1. Can Hibernate Tools generate Annotations for plain old Hibernate?
  2. Can it generate mapping information in the POJO's (i.e. @manytomany / @manytoone) ?

Thanks a lot for your help,

Bob

Colin Schofield
  • 139
  • 1
  • 13
  • Ok, so I'm pretty sure that the question to #1 is that YES, you can use it to generate Hibernate specific code that will work with Hibernate's ORM. BUT still no word on HOW you can get it to reverse engineer Foreign Key relationships to @ manytomany / @ manytoone etc. PLEASE HELP!!! – Colin Schofield Oct 15 '12 at 19:31
  • do you have the correct foreignkey constraints present in the db? – Firo Oct 16 '12 at 12:33
  • @Firo Yes I do I have a @ manytoone relationship, plus I tried it with a more complex database with plenty of @ manytomany relationships and NOTHING worked correctly. – Colin Schofield Oct 16 '12 at 17:42

2 Answers2

3

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!

Colin Schofield
  • 139
  • 1
  • 13
0

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.

Mohit
  • 807
  • 9
  • 11