0

Всем привет! Есть сущность, есть репозиторий. При запуске спринг отказывается запускаться и выдает следующее:

2021-03-15 14:08:50.721 ERROR 3468 --- [  restartedMain] o.s.boot.SpringApplication: 
Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name
'mailConfirmationRepo' defined in com.company.repos.MailConfirmationRepo defined in 
@EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Cannot 
resolve reference to bean 'jpaMappingContext' while setting bean property 'mappingContext'; nested 
exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 
'jpaMappingContext': Invocation of init method failed; nested exception is 
org.hibernate.AnnotationException: No identifier specified for entity: 
com.company.domain.MailConfirmation

Сущность:

package com.company.domain;

import lombok.Data;
import org.springframework.data.annotation.Id;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import java.util.UUID;

@Entity
@Table(name = "mail_confirmations")
@Data
public class MailConfirmation {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @Column(unique = true, nullable = false)
    private String code = UUID.randomUUID().toString().substring(0, 6);

    @Column(unique = true, nullable = false)
    private String mail;

    @Column(nullable = false)
    private boolean confirmed = false;

    public MailConfirmation() {
    }

    public MailConfirmation(String mail) {
        this.mail = mail;
    }
}

Репозиторий:

package com.company.domain;

import com.company.domain.MailConfirmation;
import org.springframework.data.jpa.repository.JpaRepository;

public interface MailConfirmationRepo extends JpaRepository<MailConfirmation, Long> {

    MailConfirmation getByCode(String code);

}

Файл миграции:

create table mail_confirmations
(
    id                int8 not null unique,
    code              varchar(6) not null unique,
    mail              varchar(255) not null,
    confirmed         boolean not null,
    primary key (id)
);

application.properties

server.port=8085

spring.jpa.database=POSTGRESQL
spring.datasource.driverClassName=org.postgresql.Driver

spring.datasource.url=${SPRING_DATASOURCE_URL:jdbc:postgresql://localhost:5432/app}
spring.datasource.username=${SPRING_DATASOURCE_USERNAME:postgres}
spring.datasource.password=${SPRING_DATASOURCE_PASSWORD:}
spring.jpa.generate-ddl=false
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect

spring.freemarker.expose-request-attributes=true

server.error.whitelabel.enabled=true

spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=validate

Заранее спасибо за ответ.

1 ответ 1

2

Я думаю Вы немного ошиблись с аннотацией, вместо аннотации org.springframework.data.annotation.Id используйте javax.persistence.Id.

Я так предполагаю, потому что увидел такой ответ https://stackoverflow.com/a/39644765/8696557. Там говорится что для реляционных баз данных используется именно вторая аннотация, PostgreSQL как раз реляционная база данных.

И в целом советую искать причину проблемы в названиях Exception и их сообщениях, в Вашем случае это было:

org.hibernate.AnnotationException: No identifier specified for entity: 
com.company.domain.MailConfirmation
1
  • Помогло. Спасибо!
    – DeMmAge
    15 мар 2021 в 18:37

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.