-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: one to one connection generates SET?
PostPosted: Tue Mar 29, 2011 5:46 am 
Newbie

Joined: Wed Mar 16, 2011 8:32 am
Posts: 4
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.