#spring-boot #kotlin #spring-data-jpa
Вопрос:
Я использую SpringBoot ,JPA и Kotlin в своем приложении . Я хочу установить связь между двумя таблицами . Я использую Первичный ключ таблицы заболеваний в качестве внешнего ключа в классе сущностей получения И первичный ключ класса сущностей пациента в качестве внешнего ключа в классе болезней, Но при запуске приложения отображается ошибка во время выполнения, как показано ниже.
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 org.hibernate.DuplicateMappingException: Table [disease] contains logical column name [patientid] referring to multiple physical column names: [patient_id], [patientid] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1804) ~[spring-beans-5.3.10.jar:5.3.10] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620) ~[spring-beans-5.3.10.jar:5.3.10] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.10.jar:5.3.10] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.10.jar:5.3.10] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.10.jar:5.3.10] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.10.jar:5.3.10] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.10.jar:5.3.10] at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1154) ~[spring-context-5.3.10.jar:5.3.10] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:908) ~[spring-context-5.3.10.jar:5.3.10] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.10.jar:5.3.10] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.5.5.jar:2.5.5] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) ~[spring-boot-2.5.5.jar:2.5.5] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434) ~[spring-boot-2.5.5.jar:2.5.5] at org.springframework.boot.SpringApplication.run(SpringApplication.java:338) ~[spring-boot-2.5.5.jar:2.5.5] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343) ~[spring-boot-2.5.5.jar:2.5.5] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1332) ~[spring-boot-2.5.5.jar:2.5.5] at com.nillmani.hospitalmanagement.HospitalManagementApplicationKt.main(HospitalManagementApplication.kt:13) ~[main/:na] Caused by: org.hibernate.DuplicateMappingException: Table [disease] contains logical column name [patientid] referring to multiple physical column names: [patient_id], [patientid] at org.hibernate.boot.internal.InFlightMetadataCollectorImpl$TableColumnNameBinding.bindLogicalToPhysical(InFlightMetadataCollectorImpl.java:920) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final] at org.hibernate.boot.internal.InFlightMetadataCollectorImpl$TableColumnNameBinding.addBinding(InFlightMetadataCollectorImpl.java:908) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final] at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.addColumnNameBinding(InFlightMetadataCollectorImpl.java:979) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final] at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.addColumnNameBinding(InFlightMetadataCollectorImpl.java:960) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final] at org.hibernate.cfg.Ejb3JoinColumn.addColumnBinding(Ejb3JoinColumn.java:788) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final] at org.hibernate.cfg.Ejb3Column.linkWithValue(Ejb3Column.java:371) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final] at org.hibernate.cfg.annotations.TableBinder.bindFk(TableBinder.java:685) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final] at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:105) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final] at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processEndOfQueue(InFlightMetadataCollectorImpl.java:1823) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final] at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processFkSecondPassesInOrder(InFlightMetadataCollectorImpl.java:1767) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final] at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1655) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final] at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:295) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final] at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:1224) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final] at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1255) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final] at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:58) ~[spring-orm-5.3.10.jar:5.3.10] at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) ~[spring-orm-5.3.10.jar:5.3.10] at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:409) ~[spring-orm-5.3.10.jar:5.3.10] at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:396) ~[spring-orm-5.3.10.jar:5.3.10] at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341) ~[spring-orm-5.3.10.jar:5.3.10] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863) ~[spring-beans-5.3.10.jar:5.3.10] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800) ~[spring-beans-5.3.10.jar:5.3.10] ... 16 common frames omitted
Болезнь.кт
package com.nillmani.hospitalmanagement.entity import com.nillmani.hospitalmanagement.entity.enum.ProblemStatus import org.jetbrains.annotations.NotNull import javax.persistence.* @Entity data class Disease( @Id @Column(name = "problemId") val problemId:Long=-1, val diseaseName:String="", val diseaseDetails:String="", val problemStatus : ProblemStatus, var status : Int=0, val patientId : Long=-1,//Basically Belongs form patientID val admissionId : Long =-1, @NotNull @ManyToOne(cascade = [CascadeType.ALL],fetch = FetchType.LAZY) @JoinColumn(name = "patientid",referencedColumnName = "patientid") val patient: Patient, @OneToMany(cascade = [CascadeType.ALL],fetch = FetchType.LAZY,mappedBy = "disease") val receipes :Listlt;Receiptgt; = ArrayList() )
Patient.kt
package com.nillmani.hospitalmanagement.entity import com.nillmani.hospitalmanagement.entity.enum.City import java.time.LocalDate import javax.persistence.* @Entity data class Patient( @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "patientid",insertable = false,updatable = false) var patientId:Long=-1, val name :String="", val lastName: String="", val phoneNumber :String="", val dateOfBirth : LocalDate= LocalDate.now(), val gender : String="", @Enumerated(EnumType.ORDINAL) val city: City, @Column(unique = true) val email:String="", var status:Int=0, @OneToMany(cascade = [CascadeType.ALL], fetch = FetchType.LAZY,mappedBy ="patient" ) val disease: MutableListlt;Diseasegt; = ArrayList(), @OneToMany(cascade = [CascadeType.ALL], fetch = FetchType.LAZY,mappedBy = "patient") val admission : Listlt;Admissionsgt; = ArrayList() )
Receipt.kt
package com.nillmani.hospitalmanagement.entity import org.springframework.beans.factory.parsing.Problem import java.time.LocalDate import javax.persistence.* @Entity data class Receipt( @Id val receiptId:Long=-1, val details:String="", val barcode: String="", val drug_details:String="", val usage:String="", val delivery_date:LocalDate= LocalDate.now(), val problemId:Long=-1, val patientId:Long=-1, val status:Int=0, @ManyToOne(optional = true, fetch = FetchType.LAZY) @JoinColumn(name = "problemId",insertable = false,updatable = false) val disease: Disease ) How can map the column to a JPA property . It already mapped with ManyToOne , What is the main cause of this type of issue.