Я пишу образовательный проект.Это простой чат.Стек бэкэнд-технологии - это Java, Jetty (сервер, веб-сокет), Hibernate 5.3.7.Final, PostgreSQL.
У меня исключение времени выполнения org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: missing column [conversation_c_id] in table [conversation_reply]
.Ошибка заставила меня повеселиться в течение нескольких дней.Буду признателен за помощь в решении этой проблемы.
Вот базовая структура части сущностей:
@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;
Схема 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)
);
Трассировка стека:
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)
На всякий случай конфигурация 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");
Спасибо.