【问题标题】:Spring Boot - custom class field in entitySpring Boot - 实体中的自定义类字段
【发布时间】:2017-11-26 20:15:20
【问题描述】:

我有 2 个自定义类,OzBakimGunlukEtkinlik。这些类不是实体。我需要在实体中使用这些类。

但我得到一个错误:

在类中定义名称为“entityManagerFactory”的 bean 创建错误 路径资源

我该如何解决这个问题?

到目前为止我得到了什么:

@Entity
@Table
@EntityListeners(AuditingEntityListener.class)
public class Rapor implements Serializable {

    @Id
    @SequenceGenerator(name = "RAPOR_SEQUENCE", sequenceName = "RAPOR_SEQUENCE", allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "RAPOR_SEQUENCE")
    private Long id;

    @Embedded
    private OzBakim ozBakim;

    @Embedded
    private GunlukEtkinlik gunlukEtkinlik;

    private Date tarih;

//Set Get
}

更新

@Embeddable
public class GunlukEtkinlik {
    private boolean anaDil;
    private boolean bahce;
    private boolean bilimDeney;
    private boolean drama;
    private boolean dans;
    private boolean fenDoga;
    private boolean gezi;
    private boolean gorselSanatlar;
    private boolean masaBasiEtkinlik;
    private boolean masal;
    private boolean matematik;
    private boolean mutfakEtkinlik;
    private boolean muzik;
    private boolean oyun;
    private boolean satranc;
    private boolean spor;
    private boolean ingilizce;
    private boolean digerDiller;
    private boolean yaraticiEtkinlik;
    private boolean ogretmenNotu;
//Set Get
}

@Embeddable
public class OzBakim {
    private int kahvalti;
    private int ogleYemegi;
    private int ikindiKahvaltisi;
    private int elYuzTuvaletTemizligi;
    private int okulFaaliyetleri;
    private int arkadasIletisim;
    private int ogleUykusu;
    private int ogretmenNotu;
    private int topluOgretmenNotu;
//Set Get
}

错误:

2017-06-23 13:53:19.791 WARN 12832 --- [main] oswcsGenericWebApplicationContext:在上下文初始化期间遇到异常 - 取消刷新尝试:org.springframework.beans.factory.BeanCreationException:创建名为“的 bean 时出错”在类路径资源 [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class] 中定义的 entityManagerFactory':调用 init 方法失败;嵌套异常是 javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory

2017-06-23 13:53:19.799 WARN 12832 --- [main] osboot.SpringApplication:错误处理失败(在类路径资源 [org/springframework/security/ config/annotation/web/configuration/WebSecurityConfiguration.class]:bean 实例化之前的 BeanPostProcessor 失败;嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建名为 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' 的 bean 时出错: bean 初始化失败;嵌套异常是 org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importRegistry' 可用)

【问题讨论】:

  • 并且那个异常会有一个嵌套的异常告诉你真正的原因。
  • 请写完整的堆栈跟踪。
  • @ozgur Yazıyorum şimdi güncellemeyle.
  • @NeilStockton 我更新了。
  • 堆栈跟踪? “e.printStackTrace”的输出 ...

标签: java spring jpa spring-boot spring-data-jpa


【解决方案1】:

我发现了错误。 :)

Repeated column in mapping for entity: com.exam.model.Rapor column: ogretmen_notu (should be mapped with insert="false" update="false")

@Entity 类中的@Embeddable 实体,这使得它可以在@Entity 类的同一个表中添加嵌入实体的列。

不能使用重复的列名。

@Embeddable
public class GunlukEtkinlik {
    .
    .
    .
    private boolean ogretmenNotu;
}

@Embeddable
public class OzBakim {
    .
    .
    .
    private int ogretmenNotu(You must change name);
}

【讨论】:

    猜你喜欢
    • 2021-01-02
    • 1970-01-01
    • 2023-03-13
    • 1970-01-01
    • 2019-07-28
    • 2021-11-21
    • 2021-11-18
    • 1970-01-01
    • 2019-08-06
    相关资源
    最近更新 更多