2012-09-22 13 views
2

當hinernate嘗試這個類映射到tomcat的下面的輸出顯示MySQL數據庫不成功:創建使用表冬眠2

/* 
*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 + '}'; 
    } 
} 

登錄

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 

回答

7

原來的錯誤是在類字段索引這是MySQL中的一個關鍵字。 我一直堅持這至少2天。做重新安裝MySQL服務器,IDE,搜索Hibernate文檔等......

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

而且我只是把這個對剛幫我和其他人誰都有同樣的問題。