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.  [ 2 posts ] 
Author Message
 Post subject: not-null property references a null or transient value
PostPosted: Tue Oct 20, 2009 5:23 am 
Beginner
Beginner

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

I got this problem and tried a lot but failed to solve. Ill straightforward...

I have two entity classes here are them
1. Caller.java (unwanted code removed)
Code:
@Entity
@Table(name="caller")

public class Caller implements Serializable{
   @Id
   @GeneratedValue(strategy=GenerationType.AUTO)
   @Column(name="caller_id")
   private int callerId;

       @OneToMany(cascade={javax.persistence.CascadeType.ALL}, mappedBy="caller", fetch=FetchType.EAGER)
   private List<Passenger> passengers = new ArrayList<Passenger>();

        public void setPassengers(List<Passenger> passengers) {
      this.passengers = passengers;
   }
   public List<Passenger> getPassengers() {
      return passengers;
   }
}


2. Passenger.java
Code:
@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;

       @ManyToOne(targetEntity=Caller.class, fetch=FetchType.LAZY, optional=false)
   @JoinColumn(name="caller_id")
   private Caller caller;
}


This is my ControllerServlet.java which retrieve data from html from and then save data.
I use Spring and Hibernate combination here.

Code:
                Caller caller = new Caller();
      Passenger passenger = null;
      
      CallerDAOImpl callerDAOImpl = (CallerDAOImpl) factory.getBean("callerDao");
      PassengerDAOImpl passengerDAOImpl = (PassengerDAOImpl) factory.getBean("passengerDao");
      
      if(userAction.equals("add")){
         ArrayList<Passenger> list = new ArrayList<Passenger>();
         for(int i=1; i<=passengerCount; i++){
            
            pFamilyName = request.getParameter("P_familyname_"+i);
            if(!pFamilyName.equals("")){
               passenger = new Passenger();
               passenger.setFamilyname(pFamilyName);
               passenger.setFirstname(request.getParameter("P_firstname_"+i));
               passenger.setMobile(request.getParameter("P_mobile_"+i));
               passenger.setRelation(request.getParameter("P_relation_"+i));
               passenger.setType(request.getParameter("P_type_"+i));
               
               list.add(passenger);
               //passengerDAOImpl.addPassenger(passenger);
            }
         }
         
         
         caller.setFirstname(firstName);
         caller.setFamilyname(familyName);
         caller.setStreet(street);
         caller.setCity(city);
         caller.setPostal(postal);
         caller.setCountry(country);
         caller.setPrimaryPhone(primaryPhone);
         caller.setAlternatePhone(alternatePhone);
         caller.setEmail(email);
         caller.setAge(age);
         caller.setNationality(nationality);
         caller.setOtherInfo(otherInfo);
         caller.setPassengers(list);
         
         callerDAOImpl.addCaller(caller);


I do not post DAO class's code here, since there are no any problem with them.

Here is the error which received when I try to save data. Sole Caller object is saved, but after assigned relationship to the classes, this goes wrong.

here is the error

Code:
org.hibernate.PropertyValueException: not-null property references a null or transient value: com.trn.Passenger.caller



please help me,
regards,
dila.


Top
 Profile  
 
 Post subject: Re: not-null property references a null or transient value
PostPosted: Tue Oct 20, 2009 9:15 am 
Newbie

Joined: Sun Oct 18, 2009 8:10 pm
Posts: 2
In Passenger.java is defined property caller as optional=false...
But I don't see in our ControllerServlet.java something like
Code:
passenger.setCaller(caller);


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.