ORA-00917:在hiberanate中使用自定义oracle序列时缺少逗号错误 [英] ORA-00917: missing comma error while using custom oracle sequence in hiberanate

查看:176
本文介绍了ORA-00917:在hiberanate中使用自定义oracle序列时缺少逗号错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在尝试在冬眠时使用我的oracle db序列时出现此错误。
i使用此声明:

  @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(); 

//从上面创建的开始新工作单元的会话创建新事务
transaction = session.beginTransaction();

session.save(user);
transaction.commit();
System.out.println(用户在数据库中成功保存);

catch(Exception ex)
{

但是我出现错误:

  2013年4月11日上午11:10:20 org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions 
错误:ORA-00917:缺少逗号

被捕获:ORA-00917:缺少逗号

任何人都可以协助解决这个问题吗?

解决方案

在Oracle中,正确的语法是 USER_ID_SEQ.nextval ,这可能是您的语法错误来自的地方。



以下是一个可以参考的代码示例:用于生成序列中的id的Oracle触发器的HIbernate问题


从链接尝试使用...

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

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


Hi i am getting this error while i am trying to use my oracle db sequence in hibernates. i am using this declaration :

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

..

and using this to persist my entity instance:

            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)
        {

but i am getting the error:

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

caught : ORA-00917: missing comma

Could anyone assist on this?

解决方案

In Oracle the correct syntax is USER_ID_SEQ.nextval so that's probably where your syntax error is coming from.

Here's an example thread with some code you can refer to: HIbernate issue with Oracle Trigger for generating id from a sequence

[Edit] From the link try using ...

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

... and upgrade to the latest Hibernate JAR

这篇关于ORA-00917:在hiberanate中使用自定义oracle序列时缺少逗号错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆