aspose file tools*
The moose likes Object Relational Mapping and the fly likes Problem while Join in hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Problem while Join in hibernate" Watch "Problem while Join in hibernate" New topic
Author

Problem while Join in hibernate

vinoth subramaniam
Ranch Hand

Joined: Jul 05, 2008
Posts: 47
Hi all i am new to hibernate, and i am trying to join two tables called person and contact.I am getting the error in mapping. Please tell whats the problem.

Person Table SQL

create table person (Personid int Not null, street char (20) not null,
contactid int not null,
constraint primary_table Primary key (personid),
constraint foreign_contact foreign key (contactid) references Contact (ID))

Contact Table SQL

create table CONTACT (ID int Not null, FIRSTNAME varchar(50), LASTNAME varchar(50), EMAIL varchar(50))


person class :



Contact Class



And here is the mapping file for contact class



And the person mapping file for person



I am getting the following error



Thanks in advance....
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

The error says it all.

You have mapped an association in your Person class between person and Contant:

so your Java class needs getter/setter methods for this property.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
vinoth subramaniam
Ranch Hand

Joined: Jul 05, 2008
Posts: 47
Can you Please explain the answer in detail. Or else can you give me some sample code or example, So that i can understand the concept. Thanks...
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

All properties in your mapping file must exist in your Java class, and all properties must have getter and setter methods so Hibernate can manipulate these values. So if you map a property "foo" which is of the type String, your class must have a getter called getFoo() that returns a String and a setter called setFoo(String) that takes a string as a parameter. Associations are the same, if foo is an association to a class called Foo you'll need the same getter and setter methods that deal with Foo objects.
 
 
subject: Problem while Join in hibernate