JAVA Javax Embedded Entity с SpringBoot и Vaadin, не может создать столбец

может быть, кто-нибудь скажет мне, почему я не могу добавить встроенную колонку в свой класс Facility.class? Я хочу создать столбец из ContactPerson.class PrimaryKeys в таблице Facility.class, после чего я хочу создать конструктор в Facility.class, чтобы добавить ContactPerson. Я новичок в SpringBoot + Jpa и Vaadin ^^ Вот сообщение об ошибке, которое я получаю, я уверен, что что-то не замечаю:

org.springframework.beans.factory.BeanCreationException: ошибка при создании bean-компонента с именем 'entityManagerFactory', определенным в ресурсе пути к классу [org / springframework / boot / autoconfigure / orm / jpa / HibernateJpaConfiguration.class]: не удалось вызвать метод инициализации; вложенное исключение - org.hibernate.MappingException: свойство компонента не найдено: id

    Caused by: org.hibernate.MappingException: component property not found: id
        at org.hibernate.mapping.Component.getProperty(Component.java:274) ~[hibernate-core-5.2.14.Final.jar:5.2.14.Final]

Facility.class

 @Entity
    public class Facility extends BaseEntity {
        public Facility(@NotBlank String number, @NotBlank String name, @NotBlank String street, String extraInformation,
                        @NotBlank String zipcode, @NotBlank String city, **ContactPerson contactPerson**) {
            this.number = number;
            this.name = name;
            this.street = street;
            this.extraInformation = extraInformation;
            this.zipcode = zipcode;
            this.city = city;
            **//this.contactPerson = contactPerson;**
        }

        @NotBlank
        @Column(unique = true)
        private String number;
        @NotBlank
        private String name;
        @NotBlank
        private String street;
        private String extraInformation;
        @NotBlank
        private String zipcode;
        @NotBlank
        private String city;

        @Embedded
        @Column(columnDefinition = "contactperson")
        private ContactPerson contactPerson;

        public String getNumber() {
            return number;
        }

        public void setNumber(String number) {
            this.number = number;
        }

        public String getName() {
            return name;
        }

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

        public String getStreet() {
            return street;
        }

        public void setStreet(String street) {
            this.street = street;
        }

        public String getExtraInformation() {
            return extraInformation;
        }

        public void setExtraInformation(String extraInformation) {
            this.extraInformation = extraInformation;
        }

        public String getZipcode() {
            return zipcode;
        }

        public void setZipcode(String zipcode) {
            this.zipcode = zipcode;
        }

        public String getCity() {
            return city;
        }

        public void setCity(String city) {
            this.city = city;
        }

        public ContactPerson getContactPerson() {
            return contactPerson;
        }

        public void setContactPerson(ContactPerson contactPerson) {
            this.contactPerson = contactPerson;
        }
    }

ContactPerson.class

@Embeddable
public class ContactPerson extends BaseEntity {
    public ContactPerson(@NotBlank String titel, @NotBlank String firstName, @NotBlank String lastName, String telefon, String mobil, @Email String email) {
        this.titel = titel;
        this.firstName = firstName;
        this.lastName = lastName;
        this.telefon = telefon;
        this.mobil = mobil;
        this.email = email;
    }

    @NotBlank
    private String titel;
    @NotBlank
    private String firstName;
    @NotBlank
    private String lastName;
    private String telefon;
    private String mobil;
    @Email
    private String email;

    public String getTitel() {
        return titel;
    }

    public void setTitel(String titel) {
        this.titel = titel;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getTelefon() {
        return telefon;
    }

    public void setTelefon(String telefon) {
        this.telefon = telefon;
    }

    public String getMobil() {
        return mobil;
    }

    public void setMobil(String mobil) {
        this.mobil = mobil;
    }

    public String getEmail() {
        return email;
    }

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

BaseEntity.class

public abstract class BaseEntity extends AbstractAggregateRoot<BaseEntity> {

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

    protected long getId() {
        return this.id;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o)
            return true;
        if (o == null || this.getClass() != o.getClass())
            return false;
        BaseEntity that = (BaseEntity) o;
        return Objects.equals(this.id, that.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(this.id);
    }

    @Override
    public String toString() {
        return "BaseEntity{" +
            "id = " + this.id +
            '}';
    }
}
Стоит ли изучать PHP в 2026-2027 годах?
Стоит ли изучать PHP в 2026-2027 годах?
Привет всем, сегодня я хочу высказать свои соображения по поводу вопроса, который я уже много раз получал в своем сообществе: "Стоит ли изучать PHP в...
Поведение ключевого слова "this" в стрелочной функции в сравнении с нормальной функцией
Поведение ключевого слова "this" в стрелочной функции в сравнении с нормальной функцией
В JavaScript одним из самых запутанных понятий является поведение ключевого слова "this" в стрелочной и обычной функциях.
Приемы CSS-макетирования - floats и Flexbox
Приемы CSS-макетирования - floats и Flexbox
Здравствуйте, друзья-студенты! Готовы совершенствовать свои навыки веб-дизайна? Сегодня в нашем путешествии мы рассмотрим приемы CSS-верстки - в...
Тестирование функциональных ngrx-эффектов в Angular 16 с помощью Jest
В системе управления состояниями ngrx, совместимой с Angular 16, появились функциональные эффекты. Это здорово и делает код определенно легче для...
Концепция локализации и ее применение в приложениях React ⚡️
Концепция локализации и ее применение в приложениях React ⚡️
Локализация - это процесс адаптации приложения к различным языкам и культурным требованиям. Это позволяет пользователям получить опыт, соответствующий...
Пользовательский скаляр GraphQL
Пользовательский скаляр GraphQL
Листовые узлы системы типов GraphQL называются скалярами. Достигнув скалярного типа, невозможно спуститься дальше по иерархии типов. Скалярный тип...
2
0
331
1

Ответы 1

После долгих попыток я выяснил, в чем проблема. ContactPerson.class после встраивания больше не является сущностью, поэтому ему не нужны расширения BaseEntity.class, но для запуска ему потребуется конструктор по умолчанию. Аннотация @Embedded не требуется в Java9

ContactPerson.class

@Embeddable
public class ContactPerson {
    public ContactPerson(@NotBlank String titel, @NotBlank String firstName, @NotBlank String lastName, String telefon, String mobil, @Email String email) {
        this.titel = titel;
        this.firstName = firstName;
        this.lastName = lastName;
        this.telefon = telefon;
        this.mobil = mobil;
        this.email = email;
    }

    public ContactPerson() {
    }

    @NotBlank
    private String titel;
    @NotBlank
    private String firstName;
    @NotBlank
    private String lastName;
    private String telefon;
    private String mobil;
    @Email
    private String email;

    public String getTitel() {
        return titel;
    }

    public void setTitel(String titel) {
        this.titel = titel;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getTelefon() {
        return telefon;
    }

    public void setTelefon(String telefon) {
        this.telefon = telefon;
    }

    public String getMobil() {
        return mobil;
    }

    public void setMobil(String mobil) {
        this.mobil = mobil;
    }

    public String getEmail() {
        return email;
    }

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

Facility.class

@Entity
public class Facility extends BaseEntity {
    public Facility(@NotBlank String number, @NotBlank String name, @NotBlank String street, String extraInformation, @NotBlank String zipcode, @NotBlank String city, ContactPerson contactPerson) {
        this.number = number;
        this.name = name;
        this.street = street;
        this.extraInformation = extraInformation;
        this.zipcode = zipcode;
        this.city = city;
        this.contactPerson = contactPerson;
    }

    public Facility() {
    }

    @NotBlank
    @Column(unique = true)
    private String number;
    @NotBlank
    private String name;
    @NotBlank
    private String street;
    private String extraInformation;
    @NotBlank
    private String zipcode;
    @NotBlank
    private String city;


    private ContactPerson contactPerson;

    public String getNumber() {
        return number;
    }

    public void setNumber(String number) {
        this.number = number;
    }

    public String getName() {
        return name;
    }

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

    public String getStreet() {
        return street;
    }

    public void setStreet(String street) {
        this.street = street;
    }

    public String getExtraInformation() {
        return extraInformation;
    }

    public void setExtraInformation(String extraInformation) {
        this.extraInformation = extraInformation;
    }

    public String getZipcode() {
        return zipcode;
    }

    public void setZipcode(String zipcode) {
        this.zipcode = zipcode;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public ContactPerson getContactPerson() {
        return contactPerson;
    }

    public void setContactPerson(ContactPerson contactPerson) {
        this.contactPerson = contactPerson;
    }
}

Другие вопросы по теме