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();
}
}
我正在 ORA:02289序列不存在
这是hibernate.cfg.xml
<hibernate-configuration>
<session-factory>
<mapping class="com.abc.bean.UserBean" />
</session-factory>
</hibernate-configuration>
Dispatcher包扫描
<context:component-scan base-package="com.abc.controller" />
<context:component-scan base-package="com.abc.dao.impl" />
<mvc:annotation-driven />
我在另一台笔记本电脑上试过同样的东西而且它有效,是什么导致了这个问题?早些时候,我试图生成一个序列,但它并没有很好地运作
执行Sql命令:
create table users(id int primary key,name varchar(20),email varchar(20),age int);
答案 0 :(得分:1)
hibernate_sequence
),则hraclenate使用oracle db的序列。您应该创建序列并在实体映射中配置它,例如:
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "user_generator")
@SequenceGenerator(name="user_generator", sequenceName = "user_seq")
@Column(name="ID",allocationSize = 1)
private Integer id;
答案 1 :(得分:0)
您使用的是哪个版本的Oracle?据我所知,11g中不支持自动增量,但12c支持自动增量..