Hibernate Exception

hi experts,

I m trying to use insert data through parent child relation ( One To Many ) in Hibernate. but I m getting below error when hibernate executes. Please tell me where i wrong ?? for you more help i m providing my both parent and child class ...

SEVERE: Initial SessionFactory creation failed.org.hibernate.MappingException: Could not determine type for: java.util.Set, for columns: [org.hibernate.mapping.Column(fm4features)]
Parent Classss

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pip;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.hibernate.annotations.CollectionOfElements;

/**
 *
 * @author sachin
 */
@Entity
@Table(name = "xydata")
public class XyData implements Serializable {
    
    private static final long serialVersionUID = 1L;
    String Longi;
    String Lat;
    short altitude;
    short angle;
    byte satellite;
    short speed;
    int objectid;
    int clientid;
    String GpsTime;
    String location;
    String city;
    String State;
    String Distance;
    Timestamp Times ;
    Set<Fm4features> fm4features = new HashSet<Fm4features>(0);

    public XyData(String Longi, String Lat, short altitude, short angle, byte satellites, short speed, int objectId, int clientId, String gpsTime,String location, String city, String state, String distance, Set<Fm4features> fm4features)
    {
        this.Longi= Longi;
        this.Lat = Lat;
        this.altitude = altitude;
        this.angle=angle;
        this.satellite=satellites;
        this.speed = speed;
        this.objectid = objectId;
        this.clientid = clientId;
        this.GpsTime= gpsTime;
        this.location=location;
        this.city = city;
        this.State=state;
        this.Distance = distance;
        this.fm4features=fm4features;


    }
    public XyData(){}

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long ID;
    @Column(name = "ID")
    public Long getID() {
        return ID;
    }

    public void setID(Long id) {
        this.ID = id;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (ID != null ? ID.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof XyData)) {
            return false;
        }
        XyData other = (XyData) object;
        if ((this.ID == null && other.ID != null) || (this.ID != null && !this.ID.equals(other.ID))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return ""+ID;
    }

  @Column(name="Longi", length=40)
   public String getLongi() {
    return Longi;
  }

  public void setLongi(String Longi) {
    this.Longi = Longi;
  }

 @Column(name="Lat", length=40)
 public String getLat() {
    return Lat;
  }

  public void setLat(String Lat) {
    this.Lat = Lat;
  }

  @Column(name="Altitude", length=40)
  public short getAltitude() {
    return altitude;
  }

  public void setAltitude(short altitude) {
    this.altitude = altitude;
  }

  @Column(name="Angle", length=40)
   public short getAngle() {
    return angle;
  }

  public void setAngle(short angle) {
    this.angle = angle;
  }

  @Column(name="Satellite", length=40)
  public byte getSatellite() {
    return satellite;
  }

  public void setSatellite(byte satellite) {
    this.satellite = satellite;
  }

  @Column(name="Speed", length=40)
  public short getSpeed() {
    return speed;
  }

  public void setSpeed(short speed) {
    this.speed = speed;
  }

  @Column(name="ObjectId", length=40)
  public int getObjectId() {
    return objectid;
  }

  public void setObjectId(int objectid) {
    this.objectid = objectid;
  }

  @Column(name="ClientId", length=40)
  public int getClientId() {
    return clientid;
  }

  public void setClientId(int clientid) {
    this.clientid = clientid;
  }

  @Column(name="GpsTime", length=40)
  public String getGpsTime() {
    return GpsTime;
  }

  public void setGpsTime(String GpsTime) {
    this.GpsTime = GpsTime;
  }

  @Column(name="Location", length=40)
  public String getLocation() {
    return location;
  }

  public void setLocation(String location) {
    this.location = location;
  }

  @Column(name="City", length=40)
  public String getCity() {
    return city;
  }

  public void setCity(String city) {
    this.city = city;
  }

    @Column(name="State", length=40)
    public String getState() {
    return State;
  }

  public void setState(String State) {
    this.State = State;
  }

   @Column(name="Distance", length=40)
    public String getDistance() {
    return Distance;
  }

  public void setDistance(String Distance) {
    this.Distance = Distance;
  }

  
  @Column(name="Times")
  public Timestamp getTimes()
  {
      return Times;
  }

  public void setTimes(Timestamp Times)
  {
      this.Times = Times;
  }

 @CollectionOfElements(targetElement = Fm4features.class)
 @OneToMany(cascade = CascadeType.ALL)
 @JoinColumn(name = "ID",referencedColumnName = "ID") //joinColumns = { @JoinColumn(name = "ID") }, inverseJoinColumns = { @JoinColumn(name = "ID") })
 public Set<Fm4features> getfm4features()
  {
     if(fm4features == null)
     {
         fm4features = new HashSet<Fm4features>();
     }
      return this.fm4features;
  }

  public void setfm4features(Set<Fm4features> fm4features)
  {
      this.fm4features = fm4features;
  }

}



=======================================================
Child Classs


package pip;

import java.io.Serializable;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;

/**
 *
 * @author sachin
 */
@Entity
@Table(name = "fm4features")
public class Fm4features implements Serializable {
    private static final long serialVersionUID = 1L;
    int ID;
    int dataId;
    String value;
    XyData new_xydata_id;

    public Fm4features(){}

    public Fm4features(int dataId, String value)
    {
       //this.ID = id;
       this.dataId = dataId;
       this.value = value;
       //this.new_xydata_id = new_xydata_id;
    }
    @Id
    @Column(name = "ID")
    public int getID() {
        return this.ID;
    }

    public void setID(int id) {
        this.ID = id;
    }

    @Column(name="DataId")
    public int getDataId() {
        return this.dataId;
    }

    public void setDataId(int dataId) {
        this.dataId = dataId;
    }

     @Column(name="Value")
    public String getValue() {
        return this.value;
    }

    public void setValue(String value) {
        this.value = value;
    }


    @ManyToOne(optional=false,targetEntity=XyData.class)
    @JoinColumn(name="ID",nullable=false, insertable=false, updatable=false)
    public XyData getXyData() {
    return this.new_xydata_id;
    }

    public void setXyData(XyData new_xydata_id) {
        this.new_xydata_id = new_xydata_id;
    }



   public boolean equals(Object other) {
         if ( (this == other ) ) return true;
		 if ( (other == null ) ) return false;
		 if ( !(other instanceof Fm4features) ) return false;
		 Fm4features castOther = ( Fm4features ) other;

		 return (this.getID()==castOther.getID())
 && (this.getDataId()==castOther.getDataId())
 && ( (this.getValue()==castOther.getValue()) || ( this.getValue()!=null && castOther.getValue()!=null && this.getValue().equals(castOther.getValue()) ) );
   }

   public int hashCode() {
         int result = 17;

         result = (int) (37 * result + this.getID());
         result = 37 * result + this.getDataId();
         result = 37 * result + ( getValue() == null ? 0 : this.getValue().hashCode() );
         return result;
   }

}





i m adding data through this code -

 Set<Fm4features> fm4 = new HashSet<Fm4features>();
            sess = HibernateUtil.getSessionFactory().getCurrentSession();
            Transaction tr = sess.beginTransaction();
              
          for (int i = 0; i < obj.length && obj[i] != 0; i++)
          {
               int all = obj[i] - 1;
              fm4.add(new Fm4features(all,obja[i]+""));
                System.out.println(all + " ::: " + obja[i]);
 
               


          }
        
            XyData xy = new XyData(xx+"",yy+"",altitude,angle,satellites,speed,objectId,clientId,sdf.format(resultdate),"N/A","N/A","N/A","0",fm4);
            sess.save(xy);
            tr.commit();


but i m facing this error ---

SEVERE: Initial SessionFactory creation failed.org.hibernate.MappingException: Could not determine type for: java.util.Set, for columns: [org.hibernate.mapping.Column(fm4features)]

Open in new window

Sachin_AjmaniAsked:
Who is Participating?
 
VenabiliConnect With a Mentor Commented:
Off through the door but http://today.java.net/article/2005/10/07/unit-testing-hibernate-mapping-configurations describes exactly this error down in one of the explanations and usually this had been the problem for me. So see if it matches. I will be looking at the code for you as soon as I can but it can take a while and hopefully someone else will be here as well =- just wanted to give you something to look at as a start.
0
 
Sachin_AjmaniAuthor Commented:
I saw your link but it is not related to my problem...
0
 
Sachin_AjmaniAuthor Commented:
hi experts i solved this error but now i m facing problem that data is inserting in only one table and no data is inserting in 2nd table please tell me where i wrong ?

actually i have 2 tables XyData and Fm4features table.

Table structures are ---- XyData have Primary Key ( Auto Generated ) and This key is Foreign Key of Fm4features table but not auto generated and Primary Key in this table because  XyData Id have 4-5 Values so our structure look like below ----



XyData Table -----


ID            Name                abc               time           ObjectId

1              asada              222               3333           7
2              232333            3333             3333           8
3              sddsd              23323          32323          9
4              xyz                  xy1z              jsjsjs          7



Fm4features  table ----------- ID must be same as XyData ID for particular ObjectId so i m using One To Many Relationship .............


So you can see the structures ------

ID                   Value
1                       0
1                       9
1                       6
3                       1
3                       1
3                       1
4                       1
4                       0  
4                       1
4                       1
4                       1
4                       1

 
I m


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pip;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.hibernate.annotations.CollectionOfElements;

/**
 *
 * @author sachin
 */
@Entity
@Table(name = "xydata")
public class XyData implements Serializable {
    
    private static final long serialVersionUID = 1L;
    String Longi;
    String Lat;
    short altitude;
    short angle;
    byte satellite;
    short speed;
    int objectid;
    int clientid;
    String GpsTime;
    String location;
    String city;
    String State;
    String Distance;
    Timestamp Times ;
    

    public XyData(String Longi, String Lat, short altitude, short angle, byte satellites, short speed, int objectId, int clientId, String gpsTime,String location, String city, String state, String distance,Set<Fm4features> fm4)
    {
        this.Longi= Longi;
        this.Lat = Lat;
        this.altitude = altitude;
        this.angle=angle;
        this.satellite=satellites;
        this.speed = speed;
        this.objectid = objectId;
        this.clientid = clientId;
        this.GpsTime= gpsTime;
        this.location=location;
        this.city = city;
        this.State=state;
        this.Distance = distance;
        this.fm4features=fm4;


    }
    public XyData(){}

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long ID;
    @Column(name = "ID")
    public Long getID() {
        return ID;
    }

    public void setID(Long id) {
        this.ID = id;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (ID != null ? ID.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof XyData)) {
            return false;
        }
        XyData other = (XyData) object;
        if ((this.ID == null && other.ID != null) || (this.ID != null && !this.ID.equals(other.ID))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return ""+ID;
    }

  @Column(name="Longi", length=40)
   public String getLongi() {
    return Longi;
  }

  public void setLongi(String Longi) {
    this.Longi = Longi;
  }

 @Column(name="Lat", length=40)
 public String getLat() {
    return Lat;
  }

  public void setLat(String Lat) {
    this.Lat = Lat;
  }

  @Column(name="Altitude", length=40)
  public short getAltitude() {
    return altitude;
  }

  public void setAltitude(short altitude) {
    this.altitude = altitude;
  }

  @Column(name="Angle", length=40)
   public short getAngle() {
    return angle;
  }

  public void setAngle(short angle) {
    this.angle = angle;
  }

  @Column(name="Satellite", length=40)
  public byte getSatellite() {
    return satellite;
  }

  public void setSatellite(byte satellite) {
    this.satellite = satellite;
  }

  @Column(name="Speed", length=40)
  public short getSpeed() {
    return speed;
  }

  public void setSpeed(short speed) {
    this.speed = speed;
  }

  @Column(name="ObjectId", length=40)
  public int getObjectId() {
    return objectid;
  }

  public void setObjectId(int objectid) {
    this.objectid = objectid;
  }

  @Column(name="ClientId", length=40)
  public int getClientId() {
    return clientid;
  }

  public void setClientId(int clientid) {
    this.clientid = clientid;
  }

  @Column(name="GpsTime", length=40)
  public String getGpsTime() {
    return GpsTime;
  }

  public void setGpsTime(String GpsTime) {
    this.GpsTime = GpsTime;
  }

  @Column(name="Location", length=40)
  public String getLocation() {
    return location;
  }

  public void setLocation(String location) {
    this.location = location;
  }

  @Column(name="City", length=40)
  public String getCity() {
    return city;
  }

  public void setCity(String city) {
    this.city = city;
  }

    @Column(name="State", length=40)
    public String getState() {
    return State;
  }

  public void setState(String State) {
    this.State = State;
  }

   @Column(name="Distance", length=40)
    public String getDistance() {
    return Distance;
  }

  public void setDistance(String Distance) {
    this.Distance = Distance;
  }

  
  @Column(name="Times")
  public Timestamp getTimes()
  {
      return Times;
  }

  public void setTimes(Timestamp Times)
  {
      this.Times = Times;
  }

 @CollectionOfElements(targetElement = Fm4features.class)
 @OneToMany(fetch=FetchType.EAGER,mappedBy="ID")
 @JoinColumn(name = "ID",referencedColumnName = "ID") //joinColumns = { @JoinColumn(name = "ID") }, inverseJoinColumns = { @JoinColumn(name = "ID") })
 public Set<Fm4features> fm4features = new HashSet<Fm4features>();
 public Set<Fm4features> getfm4features()
  {
     if(fm4features == null)
     {
         fm4features = new HashSet<Fm4features>();
     }
      return this.fm4features;
  }

  public void setfm4features(Set<Fm4features> fm4features)
  {
      this.fm4features = fm4features;
  }

}





/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pip;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;

/**
 *
 * @author sachin
 */
@Entity
@Table(name = "fm4features")
public class Fm4features implements Serializable {
    private static final long serialVersionUID = 1L;
    int ID;
    int dataId;
    String value;
    

    public Fm4features(){}

    public Fm4features(int dataId, String value)
    {
       //this.ID = id;
       this.dataId = dataId;
       this.value = value;
       
    }
    //    @GeneratedValue(generator="foreign")
//    @GenericGenerator(name="foreign", strategy = "foreign", parameters={
//    @Parameter(name="property", value="ID")
//   })

    @Id
    @Column(name = "ID")
    public int getID() {
        return this.ID;
    }

    public void setID(int id) {
        this.ID = id;
    }

    @Column(name="DataId")
    public int getDataId() {
        return this.dataId;
    }

    public void setDataId(int dataId) {
        this.dataId = dataId;
    }

     @Column(name="Value")
    public String getValue() {
        return this.value;
    }

    public void setValue(String value) {
        this.value = value;
    }


    @ManyToOne
    @JoinColumn(name="ID", insertable=false, updatable=false, nullable=false)
    XyData new_xydata_id = new XyData();
    public XyData getXyData() {
    return this.new_xydata_id;
    }

    public void setXyData( XyData  new_xydata_id) {
        this.new_xydata_id = new_xydata_id;
    }



   public boolean equals(Object other) {
         if ( (this == other ) ) return true;
		 if ( (other == null ) ) return false;
		 if ( !(other instanceof Fm4features) ) return false;
		 Fm4features castOther = ( Fm4features ) other;

		 return (this.getID()==castOther.getID())
 && (this.getDataId()==castOther.getDataId())
 && ( (this.getValue()==castOther.getValue()) || ( this.getValue()!=null && castOther.getValue()!=null && this.getValue().equals(castOther.getValue()) ) );
   }

   public int hashCode() {
         int result = 17;

         result = (int) (37 * result + this.getID());
         result = 37 * result + this.getDataId();
         result = 37 * result + ( getValue() == null ? 0 : this.getValue().hashCode() );
         return result;
   }

}




I m inserting like this ---------------

 Set<Fm4features> fm4 = new HashSet<Fm4features>();
            sess = HibernateUtil.getSessionFactory().getCurrentSession();
            Transaction tr = sess.beginTransaction();
            XyData xy = null;
              
          for (int i = 0; i < obj.length && obj[i] != 0; i++)
          {
               int all = obj[i] - 1;
              fm4.add(new Fm4features(all,obja[i]+""));
              
             


          }

             xy = new XyData(xx+"",yy+"",altitude,angle,satellites,speed,objectId,clientId,sdf.format(resultdate),"N/A","N/A","N/A","0",fm4);
           
            sess.save(xy);
            tr.commit();
         

My problem is now with the help of this code the data is inserting in only Xydata table and In Fmfeatures table no data is inserting ..
Please tell me where i wrong ??

Thanks...

Open in new window

0
 
VenabiliCommented:
Where do you save the Fmfeatures in the session and commiting them?

I see that you fo a List but I do not see any code to actually add them to the DB
0
All Courses

From novice to tech pro — start learning today.