Hi,
I am newbie to Hibernate. During my first development with hibernate I just stuck with the mapping issue. I am just trying to create a mapping b/w two very basic objects City and Area.
Following is my code:
---- Area.java ---
import java.io.Serializable;
import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table;
@Entity @Table(name="area") public class Area implements Serializable{ private static final long serialVersionUID = 788844354020585864L; @Id @GeneratedValue(strategy=GenerationType.AUTO) private Integer id; private String name; @ManyToOne @JoinColumn(name="id",nullable=false,insertable=false, updatable=false) private City city; private String description; public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; }
public City getCity() { return city; } public void setCity(City city) { this.city = city; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } }
--- City.java ---- import java.io.Serializable;
import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table;
@Entity @Table(name="city") public class City implements Serializable{
private static final long serialVersionUID = 7169196135557433984L; @Id @GeneratedValue(strategy=GenerationType.AUTO) private Integer id; private String name;
public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } }
There is no relation created in the generated tables; Furthermore if I am adding a collection of Area in the city with OneToMany annotation i got the following exception.
Initial SessionFactory creation failed.org.hibernate.MappingException: Could not determine type for: java.util.Set, for columns: [org.hibernate.mapping.Column(areas)]
Please guide me in this regard.
Thanks.
|