-->
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.  [ 3 posts ] 
Author Message
 Post subject: How to map One-To-Many relationship with annotatios
PostPosted: Mon Oct 19, 2009 11:52 pm 
Beginner
Beginner

Joined: Thu Dec 11, 2008 2:30 am
Posts: 47
Hi all,

I have two tables, one is 'caller' and other is 'passenger'
relationship is one caller can have many passengers.

in 'caller' table 'caller_id' is the primary key,
in 'passenger' table 'passenger_id' and 'caller_id' are the composite primary key.
'caller_id' is the foreign key of the 'passenger' table.

I did this like this in my classes.

Code:
package com.trn;


@Entity
@Table(name="caller")

public class Caller implements Serializable{
   @Id
   @GeneratedValue(strategy=GenerationType.AUTO)
   @Column(name="caller_id")
   private int callerId;
   
   
   @OneToMany(targetEntity=Passenger.class, mappedBy="callerId")
   @LazyCollection(LazyCollectionOption.FALSE)
   @BatchSize(size = 512)
        private List<Passenger> passengers = new ArrayList<Passenger>();
   
   public int getCallerId() {
      return callerId;
   }
   public void setCallerId(int callerId) {
      this.callerId = callerId;
   }
   
   public void setPassengers(List<Passenger> passengers) {
      this.passengers = passengers;
   }
   public List<Passenger> getPassengers() {
      return passengers;
   }
   
   
}



this is my passenger class

Code:
package com.trn;


@Entity
@Table(name="passenger")
public class Passenger implements Serializable{
   
   @Id
   @GeneratedValue(strategy=GenerationType.AUTO)
   @Column(name="passenger_id")
   private int passengerID;
   
   
   
   @Column(name="p_caller_id")
   private int callerID;
   
   
   public int getPassengerID() {
      return passengerID;
   }
   public void setPassengerID(int passengerID) {
      this.passengerID = passengerID;
   }
   
   public int getCallerID() {
      return callerID;
   }
   public void setCallerID(int callerID) {
      this.callerID = callerID;
   }
   
   
   
}



I have removed All import statements and unwanted getters and setters here.

This code gives me a error like this:

Code:
org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: com.trn.Passenger.callerId in com.trn.Caller.passengers



please help me to go through this.....

regards,
DIL.


Top
 Profile  
 
 Post subject: Re: How to map One-To-Many relationship with annotatios
PostPosted: Tue Oct 20, 2009 3:05 am 
Newbie

Joined: Sun Oct 18, 2009 8:10 pm
Posts: 2
Isn't it case sensitive ? (callerId vs. callerID)
Code:
@Entity
@Table(name="caller")
public class Caller implements Serializable{
   ...
   @OneToMany(targetEntity=Passenger.class, mappedBy="callerId") // <-- fix it here to mappedBy="callerID"
   @LazyCollection(LazyCollectionOption.FALSE)
   @BatchSize(size = 512)
   private List<Passenger> passengers = new ArrayList<Passenger>();
   ...


Code:
@Entity
@Table(name="passenger")
public class Passenger implements Serializable{
   ...
   @Column(name="p_caller_id")
   private int callerID; // or here :)
   ...


Top
 Profile  
 
 Post subject: Re: How to map One-To-Many relationship with annotatios
PostPosted: Tue Oct 20, 2009 5:09 am 
Beginner
Beginner

Joined: Thu Dec 11, 2008 2:30 am
Posts: 47
yes, that is the case, problem solved.

Now I have a real difficult problem, Ill post it under the heading name "not-null property references a null or transient value" as a new post.

thank you very much your respond.

regards,
Dilan.


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

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.