2

Am using Hibernate 3.6

Below is Employee class code.

public class Employee {

private int id;

public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}

Below is Employee.hbm.xml file,

<class name="com.testing.hibernate.Employee" table="HIB_EMPLOYEE">
      <meta attribute="class-description">
            This class contains the Employee details.
      </meta>
      <id name="id" type="int" column="id">
         <generator class="sequence"></generator>
      </id>
      <property name="firstName" column="first_name" type="string"></property>
      <property name="lastName" column="last_name" type="string"></property>
      <property name="salary" column="salary" type="int"></property>            
  </class>

I have created sequence in Database. Below SS for reference. How can I overcome the exception that am getting? enter image description here

3
  • Post your code for Query! Commented Sep 19, 2013 at 12:56
  • what is the database you are using Commented Sep 19, 2013 at 12:59
  • @samba Its Oracle 10g Commented Sep 19, 2013 at 13:13

2 Answers 2

4

You have to give the reference of the sequence to hibernate.

<generator class="sequence">
     <param name="sequence">SEQUENCE_NAME</param>
</generator>
Sign up to request clarification or add additional context in comments.

Comments

1

What annotation can i use to do this?

i've tried

@GeneratedValue(strategy=GenerationType.SEQUENCE , generator = <SEQUENCE_NAME>") without any success

edit:

it seams that the generator have to also be created

@SequenceGenerator(name="<GEN_NAME>", sequenceName="<SEQUENCE_NAME>")

1 Comment

I think that first annotation must be with generator = "<GEN_NAME>" (NOT with sequence_name)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.