gpt4 book ai didi

java - Hibernate/Oracle 序列不工作

转载 作者:行者123 更新时间:2023-11-30 04:17:12 24 4
gpt4 key购买 nike

我正在使用 hibernate 和 oracle DB 尝试使用序列将自动 ID 插入到表中。该序列确实存在于数据库中,但 hibernate 似乎无法找到它。

以下是所有相关信息:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".SLF4J: Defaulting to no-operation (NOP) logger implementationSLF4J: 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

I know it says "Caused by: java.sql.SQLSyntaxErrorException: ORA-02289: sequence does not exist" but I can access the sequence on the database:

Table:

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;
}

最佳答案

为什么同时使用 xml 和 @Annotation ?也许 xml 定义胜过注释,并且 Hibernate 正在检索默认序列而不是您的 property_seq
尝试删除 xml 映射并检查它是否有效。

关于java - Hibernate/Oracle 序列不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18081331/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com