gpt4 book ai didi

java - 无法在我的项目中创建唯一的键约束

转载 作者:行者123 更新时间:2023-12-01 18:00:53 25 4
gpt4 key购买 nike

我的表(tbl_branch_type) 存在于我的数据库中。其他所有列都在那里,但我收到此错误:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [com/example/local/config/LocalDbConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: Unable to create unique key constraint (code, bank_type_id) on table tbl_branch_type: database column 'bank_type_id' not found. Make sure that you use the correct column name which depends on the naming strategy in use (it may not be the same as the property name in the entity, especially for relational types)

我的 BranchType 实体是:

@Entity
@Table(
name = "tbl_branch_type",
uniqueConstraints = {
@UniqueConstraint(
name = "uc_branch_type_bank_id_branch_code",
columnNames = {"code", "bank_type_id"})
})
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@Getter
@Setter
@EqualsAndHashCode(
callSuper = true,
exclude = {"bankType"})
@ToString(exclude = {"bankType"})
public class BranchType extends Auditing implements Serializable {

private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq_branch_type")
@SequenceGenerator(sequenceName = "seq_branch_type", allocationSize = 1, name = "seq_branch_type")
private Long id;

@NotNull
@Size(min = 1, max = 20)
@Column(name = "code", length = 20, nullable = false)
private String code;

@NotNull
@Size(min = 1, max = 100)
@Column(name = "name", length = 100, nullable = false)
private String name;

@JsonIgnore
@ManyToOne
@JsonIgnoreProperties("")
private BankType bankType;
}

我的LocalDbConfiguration类是:

@Configuration
@PropertySource({"classpath:application.yml"})
@EnableJpaRepositories(
basePackages = {"com.example.local.model.dao", "com.example.local.core.auth.repository"})
@EnableJpaAuditing(auditorAwareRef = "auditorProvider")
public class LocalDbConfiguration {

@Primary
@Bean(name = "dataSource")
@ConfigurationProperties(prefix = "spring.datasource")
public DataSource userDataSource() {
return DataSourceBuilder.create().build();
}

@Primary
@Bean(name = "entityManagerFactory")
public LocalContainerEntityManagerFactoryBean entityManagerFactory(
EntityManagerFactoryBuilder builder, @Qualifier("dataSource") DataSource dataSource) {
Map<String, Object> properties = new HashMap<>();
properties.put("hibernate.hbm2ddl.auto", "update");
properties.put("database.platform", "org.hibernate.dialect.Oracle10gDialect");
return builder
.dataSource(dataSource)
.packages(
"com.example.local.model.entity",
"com.example.local.model.mapper",
"com.example.local.core.auth.domain")
.persistenceUnit("localPU")
.properties(properties)
.build();
}

@Primary
@Bean(name = "transactionManager")
public PlatformTransactionManager transactionManager(
@Qualifier("entityManagerFactory") EntityManagerFactory entityManagerFactory) {
return new JpaTransactionManager(entityManagerFactory);
}

@Bean
@Primary
@ConfigurationProperties("spring.datasource.hikari")
public HikariConfig defaultHikariConfig() {
return new HikariConfig();
}

@Bean
AuditorAware<Long> auditorProvider() {
return new AuditorProviderAware();
}
}

最佳答案

我相信这是您问题的根本原因:找不到数据库列“bank_type_id”。尝试创建该列

关于java - 无法在我的项目中创建唯一的键约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60631798/

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