我正在使用hibernate和oracle DB尝试使用序列将自动ID插入表中。该序列肯定存在于数据库中,但是hibernate似乎无法找到它。
以下是所有相关信息:
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;
}
答案 0 :(得分:2)
为什么你同时使用xml AND @Annotation
?也许xml定义胜过注释,而Hibernate正在重新启动默认序列,而不是property_seq
尝试删除xml映射并检查它是否有效。