Results 1 to 2 of 2
  1. #1
    megabyte is offline Member
    Join Date
    Jan 2011
    Location
    Moscow
    Posts
    5
    Rep Power
    0

    Default [newbie] Hibernate one-to-one mapping

    Hi.

    I have two classes for entities:

    PHP Code:
    @Entity
    @Table(name = "AutoCards")
    public class AutoCard implements Serializable
    {
    	@Id
    	@GeneratedValue
    	private Long id;
    
    	@OneToOne
    	@JoinColumn(name = "CityID")
    	private City city;
    
    	public City getCity() {
    		return city;
    	}
    
    	public void setCity(City city) {
    		this.city = city;
    	}
    
    	public String getCityName()
    	{
        		return getCity().getCityName();
    	}
    etc...
    and

    PHP Code:
    @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;
    	
    	public Integer getId() {
    		return id;
    	}
    
    	public void setId(Integer id) {
    		this.id = id;
    	}
    
    	public String getCityName() {
    		return cityName;
    	}
    
    	public void setCityName(String cityName) {
    		this.cityName = cityName;
    	}
    
    	public Integer getVisible() {
    		return visible;
    	}
    
    	public void setVisible(Integer visible) {
    		this.visible = visible;
    	}
    }
    When I try to use a cityName field at my JSF-page I get next message:
    PHP Code:
    java.sql.SQLException: Unknown column 'city0_.id' in 'field list'
    Could anybody help me to solve this problem?

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    Are you mapping to an already existing schema? Does the table called CITIES contain a columnd called id?

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 10:04 PM
  2. [newbie] a tool for mapping out logic?
    By jon80 in forum New To Java
    Replies: 0
    Last Post: 06-01-2009, 07:30 PM
  3. Replies: 1
    Last Post: 11-11-2008, 08:18 PM
  4. Replies: 1
    Last Post: 07-06-2007, 06:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •