Spring Boot - 实体中的自定义类字段

     2023-03-28     173

关键词:

【中文标题】Spring Boot - 实体中的自定义类字段【英文标题】:Spring Boot - custom class field in entity 【发布时间】: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”的输出 ... 【参考方案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);

【讨论】:

带有 Java/Spring Boot 的 GraphQL 无法从传递的查询中选择定义为在模式中的字段上定义的自定义指令

】带有Java/SpringBoot的GraphQL无法从传递的查询中选择定义为在模式中的字段上定义的自定义指令【英文标题】:GraphQLwithJava/SpringbootunabletopickcustomdirectivedefinedasonFieldinschemafrompassedquery【发布时间】:2021-08-1120:42:52【问题描述】:已... 查看详情

Spring Boot 中的自定义异常

】SpringBoot中的自定义异常【英文标题】:CustomExceptioninSprinBoot【发布时间】:2019-12-1209:54:06【问题描述】:我在SPRINGBOOT中编写了以下自定义错误处理程序@RestControllerAdvicepublicclassCustomGlobalExceptionHandlerextendsResponseEntityExceptionHandler@... 查看详情

无法从 Spring Boot 应用程序中的自定义 yml 文件加载配置

】无法从SpringBoot应用程序中的自定义yml文件加载配置【英文标题】:Cannotloadconfigfromcustomymlfileinspringbootapplication【发布时间】:2017-11-1608:30:55【问题描述】:我正在从我的SpringBoot服务中的application.yml加载自定义配置。我已经通... 查看详情

Spring Boot JPA中的自定义查询问题

】SpringBootJPA中的自定义查询问题【英文标题】:ProblemwithcustomQueryinSpringbootJPA【发布时间】:2020-07-0502:06:49【问题描述】:我正在尝试按范围计算记录数,但在运行服务时出现错误:Causedby:org.hibernate.hql.internal.ast.QuerySyntaxException:... 查看详情

带有spring-boot的自定义sql中的Liquibase参数

】带有spring-boot的自定义sql中的Liquibase参数【英文标题】:Liquibaseparametersincustomsqlwithspring-boot【发布时间】:2019-04-1910:16:51【问题描述】:我在jdk11上有一个spring-boot应用程序,使用maven,具有以下liquibase依赖项:<dependency><... 查看详情

Spring boot - Application.properties 中的自定义变量

】Springboot-Application.properties中的自定义变量【英文标题】:Springboot-customvariablesinApplication.properties【发布时间】:2015-11-1014:05:59【问题描述】:我有一个使用restfulapi的springboot客户端。我可以使用application.properties中的任何密钥条... 查看详情

@RepositoryRestResource 中的自定义实现

...1【问题描述】:我正在开发一个使用@RepositoryRestResource的spring-boot项目。有2个实体,Product和Domain,它们具有多对多关系。我想实现一个运行复杂查询的自定义REST调用。为了实现 查看详情

Spring Boot - 如何通过实现 BeforeAllCallback 的自定义扩展类设置或覆盖 application.yml 中定义的属性?

】SpringBoot-如何通过实现BeforeAllCallback的自定义扩展类设置或覆盖application.yml中定义的属性?【英文标题】:SpringBoot-Howtosetoroverridepropertiesdefinedinapplication.ymlviaacustomextensionclassthatimplementsBeforeAllCallback?【发布时间】:2021-01-2909:10:49 查看详情

Spring Boot,MongoDB,Pageable,按对象中的自定义方法排序

】SpringBoot,MongoDB,Pageable,按对象中的自定义方法排序【英文标题】:SpringBoot,MongoDB,Pageable,sortbyacustommethodintheobject【发布时间】:2020-04-2214:27:46【问题描述】:比如说我有以下设置,这样的模型:publicclassPost@IdprivateStringid;privat... 查看详情

Spring MVC 中的自定义授权

】SpringMVC中的自定义授权【英文标题】:CustomauthorizationinSpringMVC【发布时间】:2012-11-2520:15:01【问题描述】:我们有一个应用程序,管理员可以在其中创建用户并将角色分配给特定类型的实体。例如,如果实体名为Student,则应... 查看详情

尝试在spring boot中将env变量读取到不在application.property中的自定义属性文件

】尝试在springboot中将env变量读取到不在application.property中的自定义属性文件【英文标题】:tryingtoreadenvvariablestocustompropertiesfilenotinapplication.propertyinspringboot【发布时间】:2021-01-0510:45:27【问题描述】:我正在尝试从custom.properties... 查看详情

用于指定分发管理的自定义 spring boot 启动器

】用于指定分发管理的自定义springboot启动器【英文标题】:Customspringbootstarterforspecifyingdistributionmanagement【发布时间】:2017-01-0801:23:22【问题描述】:我们有一个SpringBoot应用程序,它的父级定义为spring-boot-starter-parent。但是在我... 查看详情

类中的字段值不会使用 Spring Boot MVC 控制器更新

】类中的字段值不会使用SpringBootMVC控制器更新【英文标题】:FieldvalueinaClassdoesnotgetupdatedwithSpringBootMVCController【发布时间】:2021-02-1823:35:03【问题描述】:我有一个包裹实体,我正在通过@PostMapping填充字段。值Volume应该从一个方... 查看详情

java - 如何在spring boot java中编写一个函数来处理JPA存储库中的自定义查询?

】java-如何在springbootjava中编写一个函数来处理JPA存储库中的自定义查询?【英文标题】:HowtowriteafunctiontohandlecustomqueryinJPArepositoryinspringbootjava?【发布时间】:2019-09-0312:14:14【问题描述】:基本上,我使用SpringBoot在服务器端托管... 查看详情

Spring Boot - 自定义 JsonDeserializer 被忽略

】SpringBoot-自定义JsonDeserializer被忽略【英文标题】:SpringBoot-CustomJsonDeserializerisignored【发布时间】:2021-05-1303:18:18【问题描述】:我正在尝试将自定义Jackson反序列化器(类“com.fasterxml.jackson.databind.JsonDeserializer”)应用于需要自... 查看详情

将实体的自定义字段与 NSPredicate 一起使用

】将实体的自定义字段与NSPredicate一起使用【英文标题】:Usinganentity\'scustomfieldwithNSPredicate【发布时间】:2014-01-1412:52:34【问题描述】:我正在尝试将自定义字段添加到实体,以便在使用NSFetchedResultsController获取对象时使用该字... 查看详情

外部tomcat中的自定义上下文路径

...43:07【问题描述】:我制作了一个想在外部tomcat8中运行的Spring-Boot应用程序。在Spring-Boot应用程序中,可以使用application.properties中的属性server.context-path选择上下文路径,但由于我使用的是外部tomcat8 查看详情

Spring Data JPA - JpaRepository 中的自定义排序

】SpringDataJPA-JpaRepository中的自定义排序【英文标题】:SpringDataJPA-CustomSortinJpaRepository【发布时间】:2016-01-2322:18:39【问题描述】:我正在将SpringDataJPA与SpringDataREST一起使用,并且我为我的Thing实体创建了一个JpaRepository。@Repositoryp... 查看详情