首页 > 解决方案 > 使用 spring-data jpa 阅读视图 - hibernate AUTO JPA 生成类型

问题描述

我有一个使用 Spring Data JPA 在 java 中读取的数据库视图。

class XView{
    private Long id;
    //Other column and constructors

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getId()
    {
        return id;
    }

    public void setId(Long id)
    {
        this.id = id;
    }

}

因此,当我尝试阅读它时,它给了我以下错误:

Caused by: java.sql.SQLException: Invalid column name 'id'.
at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:368)
at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2820)
at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2258)
at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:632)
at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQLQuery(JtdsStatement.java:477)
at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeQuery(JtdsPreparedStatement.java:778)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:82)
... 56 common frames omitted

但生成它的主要目的是因为它不存在于视图中。

标签: javahibernatesql-server-2008jpaspring-data-jpa

解决方案


推荐阅读