Greenplum中的JPA异常“lastval()不受支持”

时间:2016-05-07 12:55:30

标签: jpa greenplum

我的代码在Postgres中正常运行,但是当我切换到Greenplum时,会发生以下异常:

Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.2.v20151217-774c696): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: ERROR: lastval() not supported
Error Code: 0
Call: select lastval()
Query: ValueReadQuery(name="SEQ_GEN_IDENTITY" sql="select lastval()")
    at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:340)
    at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.processExceptionForCommError(DatabaseAccessor.java:1620)
    ...
    at org.eclipse.persistence.internal.jpa.EntityManagerImpl.flush(EntityManagerImpl.java:874)
    at org.eclipse.persistence.internal.jpa.QueryImpl.performPreQueryFlush(QueryImpl.java:967)
    at org.eclipse.persistence.internal.jpa.QueryImpl.executeReadQuery(QueryImpl.java:207)
    at org.eclipse.persistence.internal.jpa.QueryImpl.getSingleResult(QueryImpl.java:521)
    at org.eclipse.persistence.internal.jpa.EJBQueryImpl.getSingleResult(EJBQueryImpl.java:400)
    at module.AuthREST.login(AuthREST.java:103)
    ...
Caused by: org.postgresql.util.PSQLException: ERROR: lastval() not supported
    at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2157)
    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1886)
    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:555)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:417)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:302)
    at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeSelect(DatabaseAccessor.java:1009)
    at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:644)

这是用户模型类:

public class User implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id", nullable = false)
    private Long id;

    ...
}

这是AuthREST类中的代码:

...

@POST
@Path("login")
@Consumes({"application/x-www-form-urlencoded"})
public Response login(@Context HttpServletRequest request,
        @Context HttpServletResponse response,
        @FormParam("username") String username,
        @FormParam("password") String password) {

    request.login(username, password);
    ...
}

...

那么我应该如何避免Greenplum中的异常?

2 个答案:

答案 0 :(得分:1)

序列在Greenplum中的工作方式:

底层问题:序列服务器没有保留来自段服务器的请求的选项卡,因此它不知道每个段的最后一个值(或多个值)。因此无法回答lastval()。

即使序列服务器保留了已分配序列值的日志:查询的工作方式,在主服务器上执行lastval() - 但主服务器实际上从未插入任何数据。

tl; dr:在Greenplum中检索序列的最后一个值是有问题的。即使支持lastval(),返回的答案也可能不是你想要的。

答案 1 :(得分:0)

使用sql jQuery('body').on('click','.price-change',function(){ localStorage.removeItem('priceChange'); localStorage.setItem('priceChange', "priceChange"); // alert(localStorage.getItem("priceChange")); // cratejoy script to capture product ids aka <pid> etc... if(jQuery('.price-change').hasClass('selected')){ var x = document.getElementsByClassName('temp_pid'); for(var i = 0; i < x.length; i ++){ console.log(x[i].innerHTML); } }; }); 列引用序列表。您可以创建自己的最后一个值函数。

示例:

last_value