-->
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.  [ 1 post ] 
Author Message
 Post subject: Hibernate Mapping Issue
PostPosted: Mon Aug 08, 2011 5:46 pm 
Newbie

Joined: Mon Aug 08, 2011 5:13 pm
Posts: 1
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.


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

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.