2015-07-10 55 views
0

我用這 http://howtodoinjava.com/2013/03/21/spring-3-and-hibernate-integration-tutorial-with-example/無效列類型getint不是類實現oracle.jdbc.driver.t4CRowidAccessor冬眠

教程創建Spring + Hibernate的App.But我得到這個例外,而插入數據。我正在使用Oracle。

Could not insert : howtodoinjava.entity.EmployeeEntity 

invalid column type getInt not implemented for class oracle.jdbc.driver.t4CRowidAccessor 

在我使用getInt的程序中,

EmployeeDaoImpl.java

package com.howtodoinjava.dao; 

import java.util.List; 

import org.hibernate.SessionFactory; 
import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.stereotype.Repository; 

import com.howtodoinjava.entity.EmployeeEntity; 

@Repository 
public class EmployeeDaoImpl implements EmployeeDAO 
{ 
    @Autowired 
    private SessionFactory sessionFactory; 
    @Override 
    public void addEmployee(EmployeeEntity employee) { 
     this.sessionFactory.getCurrentSession().save(employee); 
    } 
    @SuppressWarnings("unchecked") 
    @Override 
    public List<EmployeeEntity> getAllEmployees() { 
     return this.sessionFactory.getCurrentSession().createQuery("from EmployeeEntity").list(); 
    } 
    @Override 
    public void deleteEmployee(Integer employeeId) { 
     EmployeeEntity employee = (EmployeeEntity) sessionFactory.getCurrentSession().load(
       EmployeeEntity.class, employeeId); 
     if (null != employee) { 
      this.sessionFactory.getCurrentSession().delete(employee); 
     } 
    } 
} 

EmployeeEntity.java

package com.howtodoinjava.entity; 

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

@Entity 
@Table(name="EMPLOYEE") 
public class EmployeeEntity 
{ 
    @Id 
    @Column(name="ID") 
    @GeneratedValue 
    private Integer id; 
    @Column(name="FIRSTNAME") 
    private String firstname; 
    @Column(name="LASTNAME") 
    private String lastname; 
    @Column(name="EMAIL") 
    private String email; 
    @Column(name="TELEPHONE") 
    private String telephone; 

public void setid(int id) 
{ 
    this.id = id; 
} 
public int getid() 
{ 
    return id; 
} 

public void setfirstname(String firstname) 
{ 
    this.firstname = firstname; 
} 
public String getfirstname() 
{ 
    return firstname; 
} 

public void setlastname(String lastname) 
{ 
    this.lastname = lastname; 
} 
public String getlastname() 
{ 
    return lastname; 
} 

public void setemail(String email) 
{ 
    this.email = email; 
} 
public String getemail() 
{ 
    return email; 
} 
public void settelephone(String telephone) 
{ 
    this.telephone = telephone; 
} 
public String gettelephone() 
{ 
    return telephone; 
} 

} 
+0

郵編和DAO –

+0

請張貼堆棧跟蹤。它看起來像是從JDBC驅動程序返回來自'getGeneratedKeys'的ROW_ID而不是生成的ID。 –

回答

0

則還可以參考本教程

http://www.ekiras.com/2015/02/maven-spring-mvc-hibernate-sitemesh-hello-world-project.html

什麼,我想你可能會缺少的是干將和班級的制定者,因此而定將無法設置類變量的值。

+0

我也添加了getters&setters。 –

+0

hibernate將ID作爲Long數據類型,而不是整數類型。請儘量使它長。 –

+0

我已經使用'私人長ID',錯誤'無效列類型getLong沒有實現類oracle.jdbc.driver.t4CRowidAccessor' –

0

有兩種方法可以解決它。

在EmployeeEntity.java

或通過EmployeeEntity.java如下變化的註解與INT更換整數

@Id 
@Column(name="ID", unique = true, nullable = false) 
@**GeneratedValue(strategy=GenerationType.SEQUENCE)** 
你的實體的