com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:未知列 [英] com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column

查看:2728
本文介绍了com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:未知列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的学生类



我有两张表Student和Address,我在这里使用hibernate 3注解。

  package net.viralpatel.contact.form; 

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table(name =STUDENT)
public class Student {

private long studentId;
private String studentName;
私人地址studentAddress;
$ b $ public Student(){
}

public Student(String studentName,Address studentAddress){
this.studentName = studentName;
this.studentAddress = studentAddress;

$ b $ @ $
@GeneratedValue
@Column(name =STUDENT_ID)
public long getStudentId(){
return this 。学生卡;
}

public void setStudentId(long studentId){
this.studentId = studentId;


@Column(name =STUDENT_NAME,nullable = false,length = 100)
public String getStudentName(){
return this.studentName;
}

public void setStudentName(String studentName){
this.studentName = studentName;


@ManyToOne(cascade = CascadeType.ALL)
public Address getStudentAddress(){
return this.studentAddress;
}

public void setStudentAddress(Address studentAddress){
this.studentAddress = studentAddress;
}

}



地址类别



  import javax.persistence.Column; 
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name =ADDRESS)
public class Address {

private long addressId;
私人字符串街道;
私人字符串城市;
私有字符串状态;
私人字符串邮政编码;
$ b公共地址(){
}

公共地址(字符串街道,字符串城市,字符串状态,字符串邮政编码){
this.street =街;
this.city = city;
this.state = state;
this.zipcode = zipcode;

$ b $ @ $
@GeneratedValue
@Column(name =ADDRESS_ID)
public long getAddressId(){
return this .addressId;
}

public void setAddressId(long addressId){
this.addressId = addressId;

$ b $ @Column(name =ADDRESS_STREET,nullable = false,length = 250)
public String getStreet(){
return this.street;
}

public void setStreet(String street){
this.street = street;


@Column(name =ADDRESS_CITY,nullable = false,length = 50)
public String getCity(){
return this.city;
}

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


@Column(name =ADDRESS_STATE,nullable = false,length = 50)
public String getState(){
return this.state;
}

public void setState(String state){
this.state = state;


@Column(name =ADDRESS_ZIPCODE,nullable = false,length = 10)
public String getZipcode(){
return this.zipcode;
}

public void setZipcode(String zipcode){
this.zipcode = zipcode;
}

}



Hibernate配置文件



 <?xml version ='1.0'encoding ='utf-8'?> 
<!DOCTYPE hibernate-configuration PUBLIC
- // Hibernate / Hibernate配置DTD // EN
http://hibernate.sourceforge.net/hibernate-configuration-3.0。 DTD>


< hibernate-configuration>
< session-factory>
< mapping class =net.viralpatel.contact.form.Contact/>
< mapping class =net.viralpatel.contact.form.Student/>
< mapping class =net.viralpatel.contact.form.Address/>
< / session-factory>

< / hibernate-configuration>



我得到了错误



com。 mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:字段列表中的未知列'student0_.studentAddress_ADDRESS_ID'



任何人都知道确切的问题是什么



帮助非常感谢,
谢谢,
Shihab。

解决方案

你的地址班怎么样?从错误中看来,你的地址对象没有address_id字段。检查您的数据库是否包含address_id。


I have two table Student and Address.I am using hibernate 3 annotation for here.

My Student class

package net.viralpatel.contact.form;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table(name = "STUDENT")
public class Student {

    private long studentId;
    private String studentName;
    private Address studentAddress;

    public Student() {
    }

    public Student(String studentName, Address studentAddress) {
        this.studentName = studentName;
        this.studentAddress = studentAddress;
    }

    @Id
    @GeneratedValue
    @Column(name = "STUDENT_ID")
    public long getStudentId() {
        return this.studentId;
    }

    public void setStudentId(long studentId) {
        this.studentId = studentId;
    }

    @Column(name = "STUDENT_NAME", nullable = false, length = 100)
    public String getStudentName() {
        return this.studentName;
    }

    public void setStudentName(String studentName) {
        this.studentName = studentName;
    }

    @ManyToOne(cascade = CascadeType.ALL)
    public Address getStudentAddress() {
        return this.studentAddress;
    }

    public void setStudentAddress(Address studentAddress) {
        this.studentAddress = studentAddress;
    }

}

Address class

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "ADDRESS")
public class Address {

    private long addressId;
    private String street;
    private String city;
    private String state;
    private String zipcode;

    public Address() {
    }

    public Address(String street, String city, String state, String zipcode) {
        this.street = street;
        this.city = city;
        this.state = state;
        this.zipcode = zipcode;
    }

    @Id
    @GeneratedValue
    @Column(name = "ADDRESS_ID")
    public long getAddressId() {
        return this.addressId;
    }

    public void setAddressId(long addressId) {
        this.addressId = addressId;
    }

    @Column(name = "ADDRESS_STREET", nullable = false, length=250)
    public String getStreet() {
        return this.street;
    }

    public void setStreet(String street) {
        this.street = street;
    }

    @Column(name = "ADDRESS_CITY", nullable = false, length=50)
    public String getCity() {
        return this.city;
    }

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

    @Column(name = "ADDRESS_STATE", nullable = false, length=50)
    public String getState() {
        return this.state;
    }

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

    @Column(name = "ADDRESS_ZIPCODE", nullable = false, length=10)
    public String getZipcode() {
        return this.zipcode;
    }

    public void setZipcode(String zipcode) {
        this.zipcode = zipcode;
    }

}

Hibernate Config File

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">


<hibernate-configuration>
    <session-factory>
        <mapping class="net.viralpatel.contact.form.Contact" />
        <mapping class="net.viralpatel.contact.form.Student" />
        <mapping class="net.viralpatel.contact.form.Address" />
    </session-factory>

</hibernate-configuration>

I got the error

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'student0_.studentAddress_ADDRESS_ID' in 'field list'

Anybody know what is the exact issue

help is highly appreciated, Thanks, Shihab.

解决方案

How does your address class look like? It seems from the error that your address object is not having an address_id field. Check your database if it contains an address_id.

这篇关于com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:未知列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆