• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Problem while Join in hibernate

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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....
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic