Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem while Join in hibernate

 
vinoth subramaniam
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
vinoth subramaniam
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic