gpt4 book ai didi

java - 使用 hibernate 序列的 Spring MVC 不存在

转载 作者:行者123 更新时间:2023-12-02 12:39:08 25 4
gpt4 key购买 nike

UserBean类

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

调度程序包扫描

<context:component-scan base-package="com.abc.controller" />
<context:component-scan base-package="com.abc.dao.impl" />
<mvc:annotation-driven />

我在另一台笔记本电脑上尝试了同样的操作并且成功了,是什么导致了问题?早些时候,我尝试生成一个序列,但效果不佳

执行的Sql命令:创建表users(id int主键,name varchar(20),email varchar(20),age int);

最佳答案

如果您使用 GenerationType.AUTO(默认全局序列名称 hibernate_sequence),则 hibernate 使用 Oracle 数据库的序列。您应该创建序列并在实体映射中配置它,例如:

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "user_generator")
@SequenceGenerator(name="user_generator", sequenceName = "user_seq")
@Column(name="ID",allocationSize = 1)
private Integer id;

关于java - 使用 hibernate 序列的 Spring MVC 不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44998283/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com