informix数据库错误码-268与-239有啥不同
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了informix数据库错误码-268与-239有啥不同相关的知识,希望对你有一定的参考价值。
是unix服务器吗,finderr 查一下有详细解释,我这没有了原来有个中文详细的资料-268 Unique constraint <constraint-name> violated.
During execution of this statement, a duplicate value was introduced
into a column or columns that a unique constraint protects. The row
with the duplicate value was not allowed into the table (not inserted
or not updated). For IBM Informix Dynamic Server, any changes that this statement
made prior to the discovery of the duplicate value have been rolled back. (The
effects of preceding statements in the transaction, if there were any, remain
in effect. They must be explicitly rolled back or committed.)
This error occurs in a logging database. However, if you are using
repeatable read isolation, error -239 will display instead.
-268错误指新插入的数据或正在更改的数据出现了2行或多行重复,并且重复部分是表的主键部分。
-239指数据重复,重复部分是表的唯一索引而非主键。
-268 唯一限制<限制名>违法。
-239 不能插入新行 — 在UNIQUE INDEX字段中有重复值。追问
谢谢咯!中文错误代码我有。就是不清楚两个的本质区别!
追答谢谢,请采纳...
参考技术A -268 主键冲突或外键冲突-239 唯一索引冲突
Hibernate/JDBC 为 Informix 数据库生成错误的 SQL
【中文标题】Hibernate/JDBC 为 Informix 数据库生成错误的 SQL【英文标题】:Hibernate/JDBC generates wrong SQL for Informix database 【发布时间】:2013-10-07 07:53:22 【问题描述】:我正在尝试使用标准 JPA 方法在我们的 Spring 应用程序中实现分页。这是一个非常简化的示例:
TypedQuery<Department> depsQuery = em.createQuery("select d from Department d", Department.class);
depsQuery.setFirstResult(20);
depsQuery.setMaxResults(10);
depsQuery.getResultList();
此查询应在 Informix 中生成类似于 select skip 20 first 10
的内容。但是,它会生成:
select first 30 department0_.id as ... from DEPARTMENT department0_
我在 JBoss 的 standalone.xml
中有 <driver-class>com.informix.jdbc.IfxDriver</driver-class>
,在 persistence.xml
文件中有 <property name="hibernate.dialect" value="org.hibernate.dialect.InformixDialect" />
。如何让 Hibernate/JDBC 产生正确的查询?
【问题讨论】:
【参考方案1】:“org.hibernate.dialect.InformixDialect”不支持限制。这是课堂上的一个 sn-p:
public boolean supportsLimitOffset()
return false;
public String getLimitString(String querySelect, int offset, int limit)
if ( offset > 0 )
throw new UnsupportedOperationException( "query result offset is not supported" );
return new StringBuffer( querySelect.length() + 8 )
.append( querySelect )
.insert( querySelect.toLowerCase().indexOf( "select" ) + 6, " first " + limit )
.toString();
您可以扩展此类以创建自定义方言。然后覆盖以上两个方法。
public boolean supportsLimitOffset()
return true;
public String getLimitString(String querySelect, int offset, int limit)
return new StringBuffer( querySelect.length() + 8 )
.append( querySelect )
.insert( querySelect.toLowerCase().indexOf( "select" ) + 6," skip " + offset + " first " + limit).toString();
【讨论】:
我最终使用了InformixDialect,但这就是解决方案,谢谢。【参考方案2】:我遇到了同样的问题,上面的答案对我没有帮助。 仅覆盖 getLimitString 方法没有任何效果。 我也必须覆盖 LimitHandler 并打开一些布尔标志。
import org.hibernate.dialect.pagination.AbstractLimitHandler;
import org.hibernate.dialect.pagination.LimitHandler;
import org.hibernate.engine.spi.RowSelection;
public class TestDialect extends org.hibernate.dialect.InformixDialect
private static final LimitHandler LIMIT_HANDLER = new AbstractLimitHandler()
@Override
public String processSql(String sql, RowSelection selection)
return getMyLimitString(sql, selection.getFirstRow(), selection.getMaxRows());
@Override
public boolean supportsLimit()
return true;
@Override
public boolean bindLimitParametersFirst()
return true; // must do, otherwise there will be an exception cause of preparedStatments
;
//
////
//
public TestDialect()
super();
@Override
public LimitHandler getLimitHandler()
return LIMIT_HANDLER;
@Override
public String getLimitString(String querySelect, int offset, int limit)
return getMyLimitString(querySelect, offset, limit);
public static String getMyLimitString(String querySelect, int offset, int limit)
/* SQL Syntax:
* SELECT FIRST <limit> ...
* SELECT SKIP <offset> FIRST <limit> ...
*/
System.out.println("TestDialect.getMyLimitString()");
if (offset < 0 || limit < 0)
throw new IllegalArgumentException("Cannot perform limit query with negative limit and/or offset value(s)");
StringBuffer limitQuery = new StringBuffer(querySelect.length() + 10);
limitQuery.append(querySelect);
int indexOfEndOfSelect = querySelect.toLowerCase().indexOf("select") + 6;
if (offset == 0)
limitQuery.insert(indexOfEndOfSelect, " first ?" );
else
limitQuery.insert(indexOfEndOfSelect, " skip ?" + " first ?" );
return limitQuery.toString();
@Override
public boolean supportsLimit()
return true;
【讨论】:
以上是关于informix数据库错误码-268与-239有啥不同的主要内容,如果未能解决你的问题,请参考以下文章
Python - Informix - 字符到数字的转换错误 (-1213)
插入记录时出现 Informix“没有这样的 DBspace”错误