简体   繁体   English

Hibernate + JPA:模式验证:缺少列

[英]Hibernate + JPA: Schema-validation: missing column

I write an educational project.我写了一个教育项目。 It's a simple chat.这是一个简单的聊天。 Stack of the backend technology is Java, Jetty (server, Web Socket), and Hibernate 5.3.7.后端技术栈是Java、Jetty(服务器、Web Socket)和Hibernate 5.3.7。 Final, PostgreSQL.最后,PostgreSQL。

I've got a runtime exception org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: missing column [conversation_c_id] in table [conversation_reply] .我有一个运行时异常org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: missing column [conversation_c_id] in table [conversation_reply] The error had been making me have fun for a couple of days.这个错误让我玩了几天。 I would be grateful for the help in solving this problem.我将不胜感激帮助解决这个问题。

Here's the basic structure of the entities part:这是实体部分的基本结构:

@Entity
@Table(name = "conversation") //public class ConversationDataSet

@Id
@SequenceGenerator(name = "cIdSequence", sequenceName = "c_id_sequence", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "cIdSequence")
@Column(name = "c_id", nullable = false, updatable = false)
private long cId;

@OneToMany(mappedBy = "conversation", cascade = CascadeType.ALL, orphanRemoval = true)
private List<ConversationReplyDataSet> conversationReplies = new ArrayList<>();



@Entity
@Table(name = "conversation_reply") //public class ConversationReplyDataSet

@Id
@SequenceGenerator(name = "crIdSequence", sequenceName = "cr_id_sequence", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "crIdSequence")
@Column(name = "cr_id", nullable = false, updatable = false)
private long crId;

@Column(name = "c_id_fk")
private long cIdFk;

@ManyToOne(fetch = FetchType.LAZY)
private ConversationDataSet conversation;

The SQL schema is: SQL 模式是:

create table conversation
(
    c_id bigint not null primary key
);

create table conversation_reply
(
    cr_id bigint not null primary key,
    c_id_fk bigint not null,
    constraint fk_c_id_fk foreign key (c_id_fk) references conversation(c_id)
);

Stack trace:堆栈跟踪:

org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: missing column [conversation_c_id] in table [conversation_reply]
at org.hibernate.tool.schema.internal.AbstractSchemaValidator.validateTable(AbstractSchemaValidator.java:136)
at org.hibernate.tool.schema.internal.GroupedSchemaValidatorImpl.validateTables(GroupedSchemaValidatorImpl.java:42)
at org.hibernate.tool.schema.internal.AbstractSchemaValidator.performValidation(AbstractSchemaValidator.java:89)
at org.hibernate.tool.schema.internal.AbstractSchemaValidator.doValidation(AbstractSchemaValidator.java:68)
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:191)
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:72)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:310)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:467)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:708)
at dbService.DBServiceImpl.createSessionFactory(DBServiceImpl.java:155)
at dbService.DBServiceImpl.<init>(DBServiceImpl.java:42)
at main.Main.main(Main.java:23)

Just in case the Hibernate configuration is:以防万一 Hibernate 配置是:

configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQL94Dialect");
configuration.setProperty("hibernate.connection.driver_class", "org.postgresql.Driver");
configuration.setProperty("hibernate.connection.url", "jdbc:postgresql://localhost:5432/chatroomdb");
configuration.setProperty("hibernate.connection.username", "someusername");
configuration.setProperty("hibernate.connection.password", "somepassword");
configuration.setProperty("hibernate.show_sql", "true");
configuration.setProperty("hibernate.hbm2ddl.auto", "validate");
//   configuration.setProperty("hibernate.implicit_naming_strategy", "legacy-jpa");

Thank you.谢谢你。

change your ManyToOne relation to this :将您的 ManyToOne 关系更改为此:

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "c_id_fk")
private ConversationDataSet conversation;

and remove this并删除这个

@Column(name = "c_id_fk")
private long cIdFk;

you can read more here https://en.wikibooks.org/wiki/Java_Persistence/ManyToOne#Example_of_a_ManyToOne_relationship_annotations你可以在这里阅读更多https://en.wikibooks.org/wiki/Java_Persistence/ManyToOne#Example_of_a_ManyToOne_relationship_annotations

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Hibernate继承:模式验证:缺少列 - Hibernate inheritance: Schema-validation: missing column Java Spring Hibernate Schema-Validation:缺少表 - Java Spring Hibernate Schema-Validation: Missing Table 架构验证:缺少表 [hibernate_sequences] - Schema-validation: missing table [hibernate_sequences] 使用Schema-validation验证除dbo结果以外的其他模式中的休眠访问表:缺少表 - Hibernate acessing table in schema other than dbo results with Schema-validation: missing table Spring Boot 项目由于 Schema-validation 无法运行:缺少序列 [hibernate_sequence] - Spring Boot project fails to run because of Schema-validation: missing sequence [hibernate_sequence] Java Hibernate -Mysql Schema-validation:列中遇到错误的列类型 - Java Hibernate -Mysql Schema-validation: wrong column type encountered in column 模式验证:使用Flyway的Hibernate生成的SQL代码缺少表[…]错误消息 - Schema-validation: missing table […] error message using flyway for a SQL code generated by Hibernate SqlServer2016,Hibernate 模式验证:缺少表,但表存在于数据库中 - SqlServer2016, Hibernate schema-validation: Missing table, but table exists in db 获取 entityManageFactory 错误。 模式验证:缺少表 [hibernate_sequence] - Getting entityManageFactory error. Schema-validation: missing table [hibernate_sequence] 为什么Hibernate模式验证无法验证模式 - Why Hibernate schema-validation fail to validate schema
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM