【问题标题】:Unsuccessful: create table using hibernate 2不成功:使用休眠 2 创建表
【发布时间】:2012-09-14 20:12:27
【问题描述】:

hinernate 尝试将此类映射到 MySQL 数据库时

/*
*To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package projekat.entities;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import javax.persistence.*;
import org.apache.tapestry5.beaneditor.NonVisual;

/**
 *
 * @author nikola
 */
@Entity
public class Student implements Serializable {

  @Id
  @NonVisual
  @GeneratedValue(strategy = GenerationType.AUTO)
  @Basic(optional = false)
  private Long kljuc;
  @Basic(optional = false)
  private String ime;
  @Basic(optional = false)
  private String prezime;
  @Basic(optional = false)
  private Integer index;
  @ManyToMany
  private List<Grupa> grupaList = new ArrayList<Grupa>();

  public NewClass() {
  }

  public Long getKljuc() {
    return kljuc;
  }

  public void setKljuc(Long kljuc) {
    this.kljuc = kljuc;
  }

  public String getIme() {
    return ime;
  }

  public void setIme(String ime) {
    this.ime = ime;
  }

  public String getPrezime() {
    return prezime;
  }

  public void setPrezime(String prezime) {
    this.prezime = prezime;
  }

  public Integer getIndex() {
    return index;
  }

  public void setIndex(Integer index) {
    this.index = index;
  }

  public List<Grupa> getGrupaList() {
    return grupaList;
  }

  public void setGrupaList(List<Grupa> grupaList) {
    this.grupaList = grupaList;
  }

  @Override
  public int hashCode() {
    int hash = 5;
    hash = 83 * hash + Objects.hashCode(this.kljuc);
    hash = 83 * hash + Objects.hashCode(this.ime);
    hash = 83 * hash + Objects.hashCode(this.prezime);
    hash = 83 * hash + Objects.hashCode(this.index);
    return hash;
  }

  @Override
  public boolean equals(Object obj) {
    if (obj == null) {
      return false;
    }
    if (getClass() != obj.getClass()) {
      return false;
    }
    final Student other = (Student) obj;
    if (!Objects.equals(this.kljuc, other.kljuc)) {
      return false;
    }
    if (!Objects.equals(this.ime, other.ime)) {
      return false;
    }
    if (!Objects.equals(this.prezime, other.prezime)) {
      return false;
    }
    if (!Objects.equals(this.index, other.index)) {
      return false;
    }
    return true;
  }

  @Override
  public String toString() {
    return "Student{" + "ime=" + ime + ", prezime=" + prezime + ", index=" + index + '}';
  }
}

tomcat 日志中显示以下输出

Unsuccessful: create table Student (kljuc bigint not null auto_increment, ime varchar(255) not null, index integer not null, prezime varchar(255) not null, primary key (kljuc))
20:03:30,540 ERROR SchemaExport:387 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'integer not null, prezime varchar(255) not null, primary key (kljuc))' at line 1

【问题讨论】:

    标签: mysql hibernate syntax-error keyword create-table


    【解决方案1】:

    原来错误出现在 MySQL 中的关键字类字段索引中。 我已经坚持了至少2天。正在重新安装 MySQL 服务器、IDE、搜索休眠文档等...

      @Basic(optional = false)
      private Integer index;
    //to
      @Basic(optional = false)
      private Integer indeks;
    

    我只是为了帮助我和其他有同样问题的人。

    【讨论】:

      猜你喜欢
      • 2012-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-15
      • 1970-01-01
      • 2011-05-01
      相关资源
      最近更新 更多