gpt4 book ai didi

java - Hibernate 未在不同架构上创建新列

转载 作者:太空宇宙 更新时间:2023-11-04 12:38:28 27 4
gpt4 key购买 nike

以下是我在其中添加了名为 banned 的新列的实体

@PersistenceUnit(unitName="persistenceUnit")
@Entity
@Table(name = "customer", schema = "customerDb")
public class CustomerEntity {
private String email;
private String password;
private Timestamp createdAt;
private String secondaryEmail;
private int id;
private Timestamp updatedAt;
private short verified;
private Timestamp lastVisitedAt;
private String name;
private String image;
private String phoneNumber;
private boolean banned;

@Basic
@Column(name = "email", nullable = false, length = 255)
public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

@Basic
@Column(name = "password", nullable = false, length = 80)
public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

@Basic
@Column(name = "createdAt", nullable = true)
public Timestamp getCreatedAt() {
return createdAt;
}

public void setCreatedAt(Timestamp createdAt) {
this.createdAt = createdAt;
}

@Basic
@Column(name = "secondaryEmail", nullable = true, length = 255)
public String getSecondaryEmail() {
return secondaryEmail;
}

public void setSecondaryEmail(String secondaryEmail) {
this.secondaryEmail = secondaryEmail;
}

@Id
@Column(name = "Id", nullable = false)
public int getId() {
return id;
}

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

@Basic
@Column(name = "updatedAt", nullable = true)
public Timestamp getUpdatedAt() {
return updatedAt;
}

public void setUpdatedAt(Timestamp updatedAt) {
this.updatedAt = updatedAt;
}

@Basic
@Column(name = "verified", nullable = false)
public short getVerified() {
return verified;
}

public void setVerified(short verified) {
this.verified = verified;
}

@Basic
@Column(name = "lastVisitedAt", nullable = true)
public Timestamp getLastVisitedAt() {
return lastVisitedAt;
}

public void setLastVisitedAt(Timestamp lastVisitedAt) {
this.lastVisitedAt = lastVisitedAt;
}

@Basic
@Column(name = "name", nullable = true, length = 255)
public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

@Basic
@Column(name = "image", nullable = true, length = 255)
public String getImage() {
return image;
}

public void setImage(String image) {
this.image = image;
}

@Basic
@Column(name = "phoneNumber", nullable = true, length = 45)
public String getPhoneNumber() {
return phoneNumber;
}

public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}

@Basic
@Column(name = "banned")
public boolean getBanned() {
return banned;
}

public void setBanned(boolean banned) {
this.banned = banned;
}
}

但是,我已经在另一个架构上配置了数据源,即

<bean class="org.apache.commons.dbcp.BasicDataSource" id="dataSource">
<property name="driverClassName" value="${dbdriverClassName}" />
<property name="url" value="jdbc:mysql://localhost:3306/community__db" />
<property name="username" value="${db-username}" />
<property name="password" value="${db-password}" />
</bean>

以下是日志:

19:17:01.951 [localhost-startStop-1] INFO  java.sql.DatabaseMetaData - HHH000262: Table not found: customer 
19:17:01.951 [localhost-startStop-1] DEBUG o.h.i.f.i.DefaultIdentifierGeneratorFactory - Setting dialect [org.hibernate.dialect.MySQL5InnoDBDialect]
19:17:01.954 [localhost-startStop-1] INFO java.sql.DatabaseMetaData - HHH000262: Table not found: customer
19:17:01.955 [localhost-startStop-1] INFO java.sql.DatabaseMetaData - HHH000262: Table not found: customer
19:17:01.955 [localhost-startStop-1] DEBUG o.h.i.f.i.DefaultIdentifierGeneratorFactory - Setting dialect [org.hibernate.dialect.MySQL5InnoDBDialect]
19:17:01.955 [localhost-startStop-1] DEBUG o.h.i.f.i.DefaultIdentifierGeneratorFactory - Setting dialect [org.hibernate.dialect.MySQL5InnoDBDialect]
19:17:01.955 [localhost-startStop-1] DEBUG o.h.i.f.i.DefaultIdentifierGeneratorFactory - Setting dialect [org.hibernate.dialect.MySQL5InnoDBDialect]
19:17:01.957 [localhost-startStop-1] DEBUG o.h.i.f.i.DefaultIdentifierGeneratorFactory - Setting dialect [org.hibernate.dialect.MySQL5InnoDBDialect]
19:17:01.957 [localhost-startStop-1] DEBUG o.h.i.f.i.DefaultIdentifierGeneratorFactory - Setting dialect [org.hibernate.dialect.MySQL5InnoDBDialect]
19:17:01.957 [localhost-startStop-1] DEBUG o.h.i.f.i.DefaultIdentifierGeneratorFactory - Setting dialect [org.hibernate.dialect.MySQL5InnoDBDialect]
19:17:01.957 [localhost-startStop-1] DEBUG o.h.i.f.i.DefaultIdentifierGeneratorFactory - Setting dialect [org.hibernate.dialect.MySQL5InnoDBDialect]
19:17:01.957 [localhost-startStop-1] DEBUG o.h.i.f.i.DefaultIdentifierGeneratorFactory - Setting dialect [org.hibernate.dialect.MySQL5InnoDBDialect]
19:17:01.957 [localhost-startStop-1] DEBUG o.h.i.f.i.DefaultIdentifierGeneratorFactory - Setting dialect [org.hibernate.dialect.MySQL5InnoDBDialect]
19:17:01.957 [localhost-startStop-1] DEBUG o.h.i.f.i.DefaultIdentifierGeneratorFactory - Setting dialect [org.hibernate.dialect.MySQL5InnoDBDialect]
19:17:01.957 [localhost-startStop-1] DEBUG o.h.i.f.i.DefaultIdentifierGeneratorFactory - Setting dialect [org.hibernate.dialect.MySQL5InnoDBDialect]
19:17:01.957 [localhost-startStop-1] DEBUG o.h.tool.hbm2ddl.SchemaUpdate - create table customerDb.customer (Id integer not null, banned TINYINT(1), createdAt datetime, email varchar(255) not null, image varchar(255), lastVisitedAt datetime, name varchar(255), password varchar(80) not null, phoneNumber varchar(45), secondaryEmail varchar(255), updatedAt datetime, verified smallint not null, primary key (Id)) ENGINE=InnoDB
19:17:01.958 [localhost-startStop-1] ERROR o.h.tool.hbm2ddl.SchemaUpdate - HHH000388: Unsuccessful: create table customerDb.customer (Id integer not null, banned TINYINT(1), createdAt datetime, email varchar(255) not null, image varchar(255), lastVisitedAt datetime, name varchar(255), password varchar(80) not null, phoneNumber varchar(45), secondaryEmail varchar(255), updatedAt datetime, verified smallint not null, primary key (Id)) ENGINE=InnoDB
19:17:01.958 [localhost-startStop-1] ERROR o.h.tool.hbm2ddl.SchemaUpdate - Table 'customer' already exists
19:17:01.958 [localhost-startStop-1] INFO o.h.tool.hbm2ddl.SchemaUpdate - HHH000232: Schema update complete
19:17:01.958 [localhost-startStop-1] DEBUG o.h.internal.NamedQueryRepository - Checking 6 named HQL queries

不应该在 customer 表中创建一个新列吗?请帮助我。提前致谢。

最佳答案

您已经有一个客户表,hibernate 不知道更改该表,它只是尝试创建一个新表。如果您没有任何有用的数据,只需删除表 customer 并重新运行。

此外,检查您的用户的权限并确保该用户可以创建表。

我从这个日志消息中得到了这个:

HHH000388: Unsuccessful: create table customerDb.customer  ....
19:17:01.958 [localhost-startStop-1] ERROR ..... - Table 'customer' already exists

关于java - Hibernate 未在不同架构上创建新列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37074717/

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