Hi. I have two MySQL tables AutoCards and Cities. AutoCard has CityID field which should be connected with CityID field of Cities. The goal is to get city name via AutoCard bean.
Here is AutoCard.java:
Code:
package vac.entities;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.JoinColumn;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.OneToOne;
import javax.persistence.OneToMany;
import javax.persistence.ManyToOne;
import javax.persistence.CascadeType;
import javax.persistence.FetchType;
import vac.entities.City;
@Entity
@Table(name = "AutoCards")
public class AutoCard implements Serializable
{
@Id
@GeneratedValue
private Long id;
@OneToOne
private City city;
public City getCity() {
return city;
}
public void setCity(City city) {
this.city = city;
}
public String getCityName()
{
getCity().setId(getCityID());
return getCity().getCityName();
}
...
@Column(name = "CityID")
private Integer cityID;
...getters and setters...
}
and City.java:
Code:
package vac.entities;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "Cities")
public class City implements Serializable
{
@Id
@GeneratedValue
private Integer id;
@Column(name = "CityName")
private String cityName;
@Column(name = "Visible")
private Integer visible;
...etc...
}
When I call getCityName method, Hibernate write next error message:
Code:
java.sql.SQLException: Unknown column 'autocard0_.city_id' in 'field list'
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2975)
com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1600)
....
Help me please! :)