Reputation: 399
UserBean Class
@Entity
@Table(name="users")
public class UserBean {
@Id
@GeneratedValue(strategy =GenerationType.AUTO)
@Column(name="ID")
private Integer id;
@Column(name = "NAME")
private String name;
@Column(name = "EMAIL")
private String email;
@Column(name = "AGE")
private int age;
/**
* @return the id
*/
public Integer getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(Integer id) {
this.id = id;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the email
*/
public String getEmail() {
return email;
}
/**
* @param email the email to set
*/
public void setEmail(String email) {
this.email = email;
}
/**
* @return the age
*/
public int getAge() {
return age;
}
/**
* @param age the age to set
*/
public void setAge(int age) {
this.age = age;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("UserBean [id=").append(id).append(", name=")
.append(name).append(", email=").append(email).append(", age=")
.append(age).append("]");
return builder.toString();
}
}
I am getting ORA:02289 Sequence doesn't exist
Here is hibernate.cfg.xml
<hibernate-configuration>
<session-factory>
<mapping class="com.abc.bean.UserBean" />
</session-factory>
</hibernate-configuration>
Dispatcher package scan
<context:component-scan base-package="com.abc.controller" />
<context:component-scan base-package="com.abc.dao.impl" />
<mvc:annotation-driven />
I have tried the same thing in another laptop and it worked, what is causing the problem? Earlier, I tried to generate a sequence but it didn't worked well
Sql command executed:
create table users(id int primary key,name varchar(20),email varchar(20),age int);
Upvotes: 0
Views: 1747
Reputation: 21
Which version of Oracle you using? As per my knowledge Auto increment not supported in 11g but supports in 12c..
Upvotes: 0
Reputation: 5407
hibernate use sequence for oracle db if you use GenerationType.AUTO (default global sequence name hibernate_sequence
) . You should create sequence and configure it in entity mapping , like :
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "user_generator")
@SequenceGenerator(name="user_generator", sequenceName = "user_seq")
@Column(name="ID",allocationSize = 1)
private Integer id;
Upvotes: 1