我正在使用hibernate和oracle數據庫嘗試使用序列將自動ID插入到表中。序列明確存在於數據庫中,但hibernate似乎無法找到它。休眠/ Oracle序列不起作用
這裏是所有相關信息:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. org.hibernate.exception.SQLGrammarException: could not get next sequence value at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) .... Caused by: java.sql.SQLSyntaxErrorException: ORA-02289: sequence does not exist .... ... 12 more
我知道它說:「產生的原因:java.sql.SQLSyntaxErrorException:ORA-02289:序列不存在」,但我可以對數據庫訪問的序列:
表:
CREATE TABLE Property(
id INT,
address VARCHAR2(50),
town VARCHAR2(50),
postCode VARCHAR2(50),
purchasePrice INT
);
序列:
create sequence property_seq start with 1 increment by 1 nomaxvalue;
XML映射:
<class name="com.rental.model.property.Property" table="PROPERTY">
<meta attribute="class-description"> This class contains the property detail. </meta>
<id name="id" type="integer" column="id">
<generator class="sequence"/>
</id>
<property name="address" column="ADDRESS" type="string" />
<property name="town" column="TOWN" type="string" />
<property name="postCode" column="POSTCODE" type="string" />
<property name="purchasePrice" column="PURCHASEPRICE" type="integer" />
</class>
註釋:
@Id
@SequenceGenerator(name="property_seq", sequenceName="property_seq", allocationSize=1, initialValue=1)
@GeneratedValue (strategy = GenerationType.SEQUENCE, generator="property_seq")
public int getId() {
return id;
}
序列對象是否在與登錄到休眠會話的用戶相同的模式中創建?如果沒有,您是否創建了同義詞並授予序列的訪問權限? – OldProgrammer
也許嘗試在property_seq上添加公共同義詞 – tbone
Hibernate使用的用戶與創建序列的用戶相同 – Paul