Как исправить ошибку «BeanCreationException» в java Spring-boot?

#java #spring #spring-boot #h2

#java #весна #spring-boot #h2

Вопрос:

У меня проблема с попыткой запустить мое приложение Spring-boot в java eclipse, и я получаю следующую ошибку:

 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.component.PojoComponentTuplizer]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1762) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1105) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
    at smartspace.Application.main(Application.java:10) [bin/:na]
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.component.PojoComponentTuplizer]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:402) ~[spring-orm-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:377) ~[spring-orm-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341) ~[spring-orm-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1821) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1758) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    ... 15 common frames omitted
Caused by: org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.component.PojoComponentTuplizer]
    at org.hibernate.tuple.component.ComponentTuplizerFactory.constructTuplizer(ComponentTuplizerFactory.java:107) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
    at org.hibernate.tuple.component.ComponentTuplizerFactory.constructDefaultTuplizer(ComponentTuplizerFactory.java:128) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
    at org.hibernate.tuple.component.ComponentMetamodel.<init>(ComponentMetamodel.java:77) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
    at org.hibernate.tuple.component.ComponentMetamodel.<init>(ComponentMetamodel.java:52) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
    at org.hibernate.mapping.Component.getType(Component.java:227) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
    at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:453) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
    at org.hibernate.mapping.Property.isValid(Property.java:226) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
    at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:624) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
    at org.hibernate.mapping.RootClass.validate(RootClass.java:267) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
    at org.hibernate.boot.internal.MetadataImpl.validate(MetadataImpl.java:347) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
    at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:466) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:939) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
    at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:57) ~[spring-orm-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) ~[spring-orm-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:390) ~[spring-orm-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    ... 19 common frames omitted
Caused by: java.lang.reflect.InvocationTargetException: null
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_191]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_191]
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_191]
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_191]
    at org.hibernate.tuple.component.ComponentTuplizerFactory.constructTuplizer(ComponentTuplizerFactory.java:104) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
    ... 33 common frames omitted
Caused by: org.hibernate.PropertyNotFoundException: Could not locate setter method for property [java.lang.String#bytes]
    at org.hibernate.internal.util.ReflectHelper.findSetterMethod(ReflectHelper.java:607) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
    at org.hibernate.property.access.internal.PropertyAccessBasicImpl.<init>(PropertyAccessBasicImpl.java:44) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
    at org.hibernate.property.access.internal.PropertyAccessStrategyBasicImpl.buildPropertyAccess(PropertyAccessStrategyBasicImpl.java:27) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
    at org.hibernate.mapping.Property.getGetter(Property.java:308) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
    at org.hibernate.tuple.component.PojoComponentTuplizer.buildGetter(PojoComponentTuplizer.java:138) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
    at org.hibernate.tuple.component.AbstractComponentTuplizer.<init>(AbstractComponentTuplizer.java:47) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
    at org.hibernate.tuple.component.PojoComponentTuplizer.<init>(PojoComponentTuplizer.java:41) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
    ... 38 common frames omitted
  

Я понятия не имею, почему он даже не запускается.
Я пытался добавлять и удалять столбцы, аннотации и т. Д…
Заранее благодарим вас за помощь!

Редактировать:

Вот классы сущностей:

Идентификатор пользователя:

 package smartspace.data;

import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Id;
import javax.persistence.Table;

//import javax.validation.constraints.Min;
//import javax.validation.constraints.NotNull;


@Entity
@Table(name = "USER")
public class UserEntity implements SmartSpaceEntity<String> {

    public static final String KEY_DELIM = "_";


    private String key; 
    private String userSmartspace;
    private String userEmail;
    private String userName;
    private String avatar;
    private UserRole role;
    private long points;

    public UserEntity() {

    }

    public UserEntity(String userSmartspace, String userEmail, String userName, String avatar, UserRole role, long points) {
        this.userSmartspace = userSmartspace;
        this.userEmail = userEmail;
        this.userName = userName;
        this.avatar = avatar;
        this.role = role;
        this.points = points;
    }

    public String getUserSmartspace() {
        return userSmartspace;
    }
    public void setUserSmartspace(String userSmartspace) {
        this.userSmartspace = userSmartspace;
    }

    @Embedded
    public String getUserEmail() {
        return userEmail;
    }
    public void setUserEmail(String userEmail) {
        this.userEmail = userEmail;
    }

    public String getUserName() {
        return userName;
    }
    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getAvatar() {
        return avatar;
    }
    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    @Enumerated(EnumType.STRING)
    public UserRole getRole() {
        return role;
    }
    public void setRole(UserRole role) {
        this.role = role;
    }

    public long getPoints() {
        return points;
    }
    public void setPoints(long points) {
        this.points = points;
    }

    @Override
    @Id
    @Column(name="ID")
    public String getKey() {
        return key;
    }

    @Override
    public void setKey(String key) {
        this.key = key;
    }

    @Override
    public String toString() {
        return "UserEntity [userSmartspace="   userSmartspace   ", userEmail="   userEmail   ", username="   userName
                  ", avatar="   avatar   ", role="   role   ", points="   points   "]";
    }

}
  

ElementEntity:

 package smartspace.data;

import java.util.Date;
import java.util.Map;

import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Embedded;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
//import javax.persistence.Transient;

import smartspace.dao.rdb.MapToJsonConverter;


@Entity
@Table(name="ELEMENT")
public class ElementEntity implements SmartSpaceEntity<Long> {

    private long id;
    private String elementSmartspace;
    private String elementId;
    private Location location;
    private String name;
    private String type;
    private Date creationTimestamp;
    private boolean expired;
    private String creatorSmartspace;
    private String creatorEmail;
    private Map<String, Object> moreAttributes;

    public ElementEntity() {

    }

    public ElementEntity(String elementSmartspace, String elementId, Location location, String name, String type,
            Date creationTimestamp, boolean expired, String creatorSmartspace, String creatorEmail,
            Map<String, Object> moreAttributes) {
        super();
        this.elementSmartspace = elementSmartspace;
        this.elementId = elementId;
        this.location = location;
        this.name = name;
        this.type = type;
        this.creationTimestamp = creationTimestamp;
        this.expired = expired;
        this.creatorSmartspace = creatorSmartspace;
        this.creatorEmail = creatorEmail;
        this.moreAttributes = moreAttributes;
    }

    public String getElementSmartspace() {
        return elementSmartspace;
    }
    public void setElementSmartspace(String elementSmartspace) {
        this.elementSmartspace = elementSmartspace;
    }

    public String getElementId() {
        return elementId;
    }
    public void setElementId(String elementId) {
        this.elementId = elementId;
    }

    @Embedded
    public Location getLocation() {
        return location;
    }
    public void setLocation(Location location) {
        this.location = location;
    }

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

    public String getType() {
        return type;
    }
    public void setType(String type) {
        this.type = type;
    }

    @Temporal(TemporalType.TIMESTAMP)
    public Date getCreationTimestamp() {
        return creationTimestamp;
    }
    public void setCreationTimestamp(java.util.Date creationTimestamp) {
        this.creationTimestamp = creationTimestamp;
    }

    public boolean isExpired() {
        return expired;
    }
    public void setExpired(boolean expired) {
        this.expired = expired;
    }

    public String getCreatorSmartspace() {
        return creatorSmartspace;
    }
    public void setCreatorSmartspace(String creatorSmartspace) {
        this.creatorSmartspace = creatorSmartspace;
    }

    public String getCreatorEmail() {
        return creatorEmail;
    }
    public void setCreatorEmail(String creatorEmail) {
        this.creatorEmail = creatorEmail;
    }

    @Lob
    @Convert(converter=MapToJsonConverter.class)
    public Map<String, Object> getMoreAttributes() {
        return moreAttributes;
    }

    public void setMoreAttributes(Map<String, Object> moreAttributes) {
        this.moreAttributes = moreAttributes;
    }

    @Override
    @Id
    @Column(name="ID")
    public Long getKey() {
        return this.id;
    }

    @Override
    public void setKey(Long key) {
        this.id = key;

    }

    @Override
    public String toString() {
        return "ElementEntity [elementSmartspace="   elementSmartspace   ", elementId="   elementId   ", location="
                  location   ", name="   name   ", type="   type   ", creationTimestamp="   creationTimestamp
                  ", expired="   expired   ", creatorSmartspace="   creatorSmartspace   ", creatorEmail="   creatorEmail
                  ", moreAttributes="   moreAttributes   "]";
    }

}
  

ActionEntity:

 package smartspace.data;

import java.util.Date;
import java.util.Map;

import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import smartspace.dao.rdb.MapToJsonConverter;

@Entity
@Table(name="ACTION")
public class ActionEntity implements SmartSpaceEntity<Long> {

    private long id;
    private String actionSmartspace;
    private String actionId;
    private String elementSmartspace;
    private String elementId;
    private String playerSmartspace;
    private String playerEmail;
    private String actionType;
    private Date creationTimestamp;
    private Map<String, Object> moreAttributes;


    public ActionEntity() {

    }

    public ActionEntity(String actionSmartspace, String actionId, String elementSmartspace, String elementId,
            String playerSmartspace, String playerEmail, String actionType, Date creationTimestamp,
            Map<String, Object> moreAttributes) {
        this.actionSmartspace = actionSmartspace;
        this.actionId = actionId;
        this.elementSmartspace = elementSmartspace;
        this.elementId = elementId;
        this.playerSmartspace = playerSmartspace;
        this.playerEmail = playerEmail;
        this.actionType = actionType;
        this.creationTimestamp = creationTimestamp;
        this.moreAttributes = moreAttributes;
    }

    public String getActionSmartspace() {
        return actionSmartspace;
    }
    public void setActionSmartspace(String actionSmartspace) {
        this.actionSmartspace = actionSmartspace;
    }

    public String getActionId() {
        return actionId;
    }
    public void setActionId(String actionId) {
        this.actionId = actionId;
    }

    public String getElementSmartspace() {
        return elementSmartspace;
    }
    public void setElementSmartspace(String elementSmartspace) {
        this.elementSmartspace = elementSmartspace;
    }

    public String getElementId() {
        return elementId;
    }

    public void setElementId(String elementId) {
        this.elementId = elementId;
    }

    public String getPlayerSmartspace() {
        return playerSmartspace;
    }

    public void setPlayerSmartspace(String playerSmartspace) {
        this.playerSmartspace = playerSmartspace;
    }

    public String getPlayerEmail() {
        return playerEmail;
    }

    public void setPlayerEmail(String playerEmail) {
        this.playerEmail = playerEmail;
    }

    public String getActionType() {
        return actionType;
    }

    public void setActionType(String actionType) {
        this.actionType = actionType;
    }

    @Temporal(TemporalType.TIMESTAMP)
    public Date getCreationTimestamp() {
        return creationTimestamp;
    }

    public void setCreationTimestamp(java.util.Date creationTimestamp) {
        this.creationTimestamp = creationTimestamp;
    }

    @Lob
    @Convert(converter=MapToJsonConverter.class)
    public Map<String, Object> getMoreAttributes() {
        return moreAttributes;
    }

    public void setMoreAttributes(Map<String, Object> moreAttributes) {
        this.moreAttributes = moreAttributes;
    }

    @Override
    @Id
    @Column(name="ID")
    public Long getKey() {
        return id;
    }

    @Override 
    public void setKey(Long key) {
        this.id = key;
    }

    @Override
    public String toString() {
        return "ActionEntity [actionSmartspace="   actionSmartspace   ", actionId="   actionId   ", elementSmartSpace="
                  elementSmartspace   ", elementId="   elementId   ", playerSmartspace="   playerSmartspace
                  ", playerEmail="   playerEmail   ", actionType="   actionType   ", creationTimestamp="
                  creationTimestamp   ", moreAttributes="   moreAttributes   "]";
    }

}
  

Как вы можете видеть, я добавил столбец «ID» к каждой сущности и назвал таблицы соответствующим образом.

Комментарии:

1. Также вы можете опубликовать свои классы сущностей? Это проблема с именем свойства

2. @Ros5292 конечно, добавил 🙂

3. PropertyNotFoundException указывает, что ожидаемый метод установки не может быть найден в классе.

4. @Ros5292 Ммм .. где я могу это получить?

5. Вы пробовали отладку? Попробуйте установить точку останова ReflectHelper.findSetterMethod и посмотреть, какой установщик не найден. Это должно указать вам правильное направление.

Ответ №1:

Ответ на ваш вопрос содержится в самом вашем вопросе :

 Caused by: org.hibernate.PropertyNotFoundException: Could not locate setter method for property [java.lang.String#bytes]
  

вам не хватает установщика для одного из ваших классов. Убедитесь, что все ваши классы имеют установщики и получатели.