Hi!
I have been fighting with this problem now two days and I am done, head is empty and I can't continue. I am using MySQLWorkbench to model a database, so I get SQL-scripts. After that I am using Hibernate tool in Eclipse to generate xml and java codes.
Problem is that I have ADDRESS-table, COMPANY and BRANCH. I would like to make that kind of structure that company can have one address and many branches. Every Branch can have one address too. No I have one to one connection between COMPANY and ADDRESS and one-to-many connection between COMPANY and BRANCH. SQL script is ok, but when I am using Hibernatetool I get every time errormessage lika that:
org.hibernate.MappingException: Foreign key (FK754219A212F4C577:BRANCH [COMPANY_companyID])) must have same number of columns as the referenced primary key (COMPANY [companyID,ADDRESS_addressId]) Foreign key (FK754219A212F4C577:BRANCH [COMPANY_companyID])) must have same number of columns as the referenced primary key (COMPANY [companyID,ADDRESS_addressId]) <No message>
If I correct this like changing COMPANY tables AddressId not identifying (FK) I get strange code:
* Address generated by hbm2java */ public class Address implements java.io.Serializable {
private int addressId; private String name; private String address1; private String address2; private String zip; private String city; private String country; private Set emails = new HashSet(0); private Set phoneses = new HashSet(0); *******private Set companies = new HashSet(0);*********
How I can get a SET even if I have one to one connection?? How I should implement that to avoid that kind of problems, pls help?
QUESTION 2
Same table ADDRESS has one to many connection to EMAILS table. Why Hibernate tool generates Address attribute under Email-class? There is Set of emails in Address object like it should be, but why there is Address in Email object?
public class Email implements java.io.Serializable {
private EmailId id; ***private Address address;****? private Integer type;
Sorry for my English, hope someone could help me :) Sami
|