2011-07-04 26 views
3

我有一個Hibernate的問題。當我想保存對象到數據庫中,我得到這個異常:org.hibernate.exception.GenericJDBCException:無法獲得下一個序列值

org.hibernate.exception.GenericJDBCException: could not get next sequence value 
25P02, current transaction is aborted, commands ignored until end of transaction block 

我的Hibernate配置文件是:

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" 
            "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> 
<hibernate-configuration> 
<session-factory name=""> 
    <!-- Database connection settings --> 
    <property name="connection.driver_class">org.postgresql.Driver</property> 
    <property name="connection.url">jdbc:postgresql://localhost:5432/3encult</property> 
    <property name="connection.username">3encult</property> 
    <property name="connection.password">3encult</property> 
    <!-- JDBC connection pool (use the built-in) --> 
    <property name="connection.pool_size">10</property> 
    <!-- SQL dialect --> 
    <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property> 
    <!-- Enable Hibernate's automatic session context management --> 
    <property name="current_session_context_class">thread</property> 
    <!-- Disable the second-level cache 
    Echo all executed SQL to stdout --> 
    <property name="show_sql">true</property> 
    <!-- Drop and re-create the database schema on startup 
    <property name="hbm2ddl.auto">create</property>--> 
    <mapping resource="resources/User.hbm.xml"/> 
    <mapping resource="resources/ApplicationField.hbm.xml"/> 
    <mapping resource="resources/Attribute.hbm.xml"/> 
    <mapping resource="resources/Device.hbm.xml"/> 
    <mapping resource="resources/Role.hbm.xml"/> 
    </session-factory> 
</hibernate-configuration> 

我的Hibernate映射文件:

<?xml version="1.0"?> 
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" 
           "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> 
<!-- Generated 07-abr-2011 13:29:19 by Hibernate Tools 3.4.0.CR1 --> 
<hibernate-mapping> 
<class name="com.cartif.database.Attribute" table="Attribute"> 
    <id name="iAttrId" column="attributeid" type="java.lang.Integer"> 
    <generator class="native"> 
    <param name="sequence">s_attribute</param> 
    </generator> 
</id> 
<property column="name" generated="never" lazy="false" name="name" type="java.lang.String"/> 
<property column="value" generated="never" lazy="false" name="value" type="java.lang.String"/> 
<property column="timestamp" generated="never" lazy="false" name="date" type="java.sql.Timestamp"/> 
<property column="deviceId" generated="never" lazy="false" name="iDeviceId" type="java.lang.Integer"/> 
<property column="sensorId" generated="never" lazy="false" name="iSensorId" type="java.lang.Integer"/> 
</class> 
</hibernate-mapping> 

屬性iAttrId存在,並且它具有get/set方法和列屬性id,表的Attribute也存在。

休眠顯示了SQL querys,它們是:

Hibernate: select nextval ('s_attribute') 
Hibernate: insert into Attribute (name, value, timestamp, deviceId, sensorId, attributeid) values (?, ?, ?, ?, ?, ?) 

的原因是什麼?

謝謝!

回答

1

我已刪除以前的序列,並生成一個新的序列,它工作正常!

1

您是否在PostgreSQL中創建了一個序列?這就像甲骨文那樣。這張桌子本身是不夠的;你也必須創建一個序列。

+0

是的,我有一個序列的名稱:s_attribute –

相關問題