1

嗨,当我尝试在休眠中使用我的 oracle db 序列时,我收到了这个错误。我正在使用这个声明:

@Entity
@Table(name = "T_USER_DETAILS")
public class User {


@GenericGenerator(name = "generator",strategy = "sequence-identity",parameters = { @Parameter(name = "sequence",value = "USER_ID_SEQ")} )
@Id 
@GeneratedValue(generator = "generator")
@Column(name = "USER_ID")
private int userid;

..

并使用它来持久化我的实体实例:

            session = sessionFactory.openSession();

        //creating the new transaction from the above created session that is starting a new unit of work
        transaction = session.beginTransaction();

        session.save(user);
        transaction.commit();
        System.out.println("User saved successfully in the database");
        }
        catch(Exception ex)
        {

但我收到错误:

Apr 11, 2013 11:10:20 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: ORA-00917: missing comma

caught : ORA-00917: missing comma

有人可以帮忙吗?

4

1 回答 1

0

在 Oracle 中,正确USER_ID_SEQ.nextval的语法可能就是您的语法错误的来源。

这是一个示例线程,其中包含一些您可以参考的代码:HIbernate issue with Oracle Trigger for generate id from a sequence

[编辑]从链接尝试使用...

@Id
@GeneratedValue(strategy=GenerationType.AUTO, generator="a1")
@SequenceGenerator(name="a1", sequenceName="USER_ID_SEQ")
@Column(name = "USER_ID")
private int userid;

...并升级到最新的 Hibernate JAR

于 2013-04-15T20:13:44.213 回答