簡體   English   中英

類別oracle.jdbc.driver.t4CRowidAccessor休眠未實現無效的列類型getint

[英]invalid column type getint not implemented for class oracle.jdbc.driver.t4CRowidAccessor hibernate

我正在使用這個http://howtodoinjava.com/2013/03/21/spring-3-and-hibernate-integration-tutorial-with-example/

創建Spring + Hibernate應用程序的教程。但是在插入數據時出現此異常。 我正在使用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;
}

}

您也可以參考本教程

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

我認為您可能缺少的是該類的getter和setter,因此,它將無法為該類變量設置值。

有兩種解決方法。

在EmployeeEntity.java中將Integer替換為int

或通過更改EmployeeEntity.java中生成的注釋,如下所示

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM