当前位置: 首页 > 知识库问答 >
问题:

org.springframework.dao.InvalidDataAccessApiUsage异常:同一实体的多个表示

仰翰采
2023-03-14

欢迎光临!

我见过同样的问题,但是解决方案对我没有帮助。

问题出现在我试图再去看牙医时。我添加了hashCode和equals方法,但没有任何帮助。移除级联类型。从访问中合并也没有帮助。我没法把它去掉。从牙医处合并,因为这样会出现另一个问题,在将访问添加到牙医之前,该访问必须存在。

堆栈跟踪:

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: Multiple representations of the same entity [com.virtualdent.entity.Visit#1] are being merged. Detached: [Visit [id=1, day=asd, time=999]]; Detached: [Visit [id=1, day=Monday, time=12]]; nested exception is java.lang.IllegalStateException: Multiple representations of the same entity [com.virtualdent.entity.Visit#1] are being merged. Detached: [Visit [id=1, day=asd, time=999]]; Detached: [Visit [id=1, day=Monday, time=12]]
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1013)
    org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:908)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)


Root Cause
org.springframework.dao.InvalidDataAccessApiUsageException: Multiple representations of the same entity [com.virtualdent.entity.Visit#1] are being merged. Detached: [Visit [id=1, day=asd, time=999]]; Detached: [Visit [id=1, day=Monday, time=12]]; nested exception is java.lang.IllegalStateException: Multiple representations of the same entity [com.virtualdent.entity.Visit#1] are being merged. Detached: [Visit [id=1, day=asd, time=999]]; Detached: [Visit [id=1, day=Monday, time=12]]
    org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:370)
    org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:528)
    org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:61)
    org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:242)
    org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:153)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:135)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:61)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
    com.sun.proxy.$Proxy46.save(Unknown Source)
    com.virtualdent.service.DentistServiceImpl.saveDentist(DentistServiceImpl.java:32)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    java.lang.reflect.Method.invoke(Unknown Source)
    org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:343)
    org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
    org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294)
    org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
    com.sun.proxy.$Proxy55.saveDentist(Unknown Source)
    com.virtualdent.controller.DentistController.saveVisit(DentistController.java:63)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    java.lang.reflect.Method.invoke(Unknown Source)
    org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:189)
    org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
    org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895)
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:800)
    org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1038)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005)
    org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:908)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)


Root Cause
java.lang.IllegalStateException: Multiple representations of the same entity [com.virtualdent.entity.Visit#1] are being merged. Detached: [Visit [id=1, day=asd, time=999]]; Detached: [Visit [id=1, day=Monday, time=12]]
    org.hibernate.event.internal.EntityCopyNotAllowedObserver.entityCopyDetected(EntityCopyNotAllowedObserver.java:45)
    org.hibernate.event.internal.MergeContext.put(MergeContext.java:245)
    org.hibernate.event.internal.DefaultMergeEventListener.entityIsDetached(DefaultMergeEventListener.java:285)
    org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:151)
    org.hibernate.internal.SessionImpl.fireMerge(SessionImpl.java:927)
    org.hibernate.internal.SessionImpl.merge(SessionImpl.java:897)
    org.hibernate.engine.spi.CascadingActions$6.cascade(CascadingActions.java:261)
    org.hibernate.engine.internal.Cascade.cascadeToOne(Cascade.java:490)
    org.hibernate.engine.internal.Cascade.cascadeAssociation(Cascade.java:415)
    org.hibernate.engine.internal.Cascade.cascadeProperty(Cascade.java:216)
    org.hibernate.engine.internal.Cascade.cascadeCollectionElements(Cascade.java:523)
    org.hibernate.engine.internal.Cascade.cascadeCollection(Cascade.java:455)
    org.hibernate.engine.internal.Cascade.cascadeAssociation(Cascade.java:418)
    org.hibernate.engine.internal.Cascade.cascadeProperty(Cascade.java:216)
    org.hibernate.engine.internal.Cascade.cascade(Cascade.java:149)
    org.hibernate.event.internal.DefaultMergeEventListener.cascadeOnMerge(DefaultMergeEventListener.java:441)
    org.hibernate.event.internal.DefaultMergeEventListener.entityIsDetached(DefaultMergeEventListener.java:307)
    org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:151)
    org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:65)
    org.hibernate.internal.SessionImpl.fireMerge(SessionImpl.java:905)
    org.hibernate.internal.SessionImpl.merge(SessionImpl.java:891)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    java.lang.reflect.Method.invoke(Unknown Source)
    org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:308)
    com.sun.proxy.$Proxy43.merge(Unknown Source)
    org.springframework.data.jpa.repository.support.SimpleJpaRepository.save(SimpleJpaRepository.java:492)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    java.lang.reflect.Method.invoke(Unknown Source)
    org.springframework.data.repository.core.support.RepositoryComposition$RepositoryFragments.invoke(RepositoryComposition.java:359)
    org.springframework.data.repository.core.support.RepositoryComposition.invoke(RepositoryComposition.java:200)
    org.springframework.data.repository.core.support.RepositoryFactorySupport$ImplementationMethodExecutionInterceptor.invoke(RepositoryFactorySupport.java:644)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:608)
    org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$invoke$3(RepositoryFactorySupport.java:595)
    org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:595)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:59)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294)
    org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:135)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:61)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
    com.sun.proxy.$Proxy46.save(Unknown Source)
    com.virtualdent.service.DentistServiceImpl.saveDentist(DentistServiceImpl.java:32)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    java.lang.reflect.Method.invoke(Unknown Source)
    org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:343)
    org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
    org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294)
    org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
    com.sun.proxy.$Proxy55.saveDentist(Unknown Source)
    com.virtualdent.controller.DentistController.saveVisit(DentistController.java:63)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    java.lang.reflect.Method.invoke(Unknown Source)
    org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:189)
    org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
    org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895)
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:800)
    org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1038)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005)
    org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:908)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

我的班级:

@Entity
@Table(name="dentysta")
public class Dentist implements Serializable{

    private static final long serialVersionUID = 3128830699411486597L;

    @Id
    @GeneratedValue
    private int id;

    @Column
    private String firstName;

    @Column
    private String lastName;

    @Column
    private String specialization;

    @Column
    private int number;

    @Column
    private String address;

    @OneToMany(mappedBy="dentist",cascade= {CascadeType.DETACH,CascadeType.MERGE,CascadeType.PERSIST,CascadeType.REFRESH},fetch=FetchType.EAGER)
    private List<Patient>patients;

    @ManyToMany(mappedBy="dentists", cascade=CascadeType.ALL)
    @LazyCollection(LazyCollectionOption.FALSE)
    private List<Visit>visits;

    public Dentist() {
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    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 getSpecialization() {
        return specialization;
    }

    public void setSpecialization(String specialization) {
        this.specialization = specialization;
    }

    public int getNumber() {
        return number;
    }

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

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }


    public List<Patient> getPatients() {
        return patients;
    }


    public void setPatients(List<Patient> patients) {
        this.patients = patients;
    }



    public List<Visit> getVisits() {
        return visits;
    }

    public void setVisits(List<Visit> visits) {
        this.visits = visits;
    }

    public void addPatient(Patient patient)
    {
        System.out.println("DENTIST=PATIENT+ADDER");

        if(patients==null) {
        patients=new ArrayList<>();
        }

        patient.setDentist(this);
        patients.add(patient);
    }

    public void addVisit(Visit visit)
    {
        if(visits==null)
        {
            visits=new ArrayList<>();
        }
        visit.addDentist(this);
        visits.add(visit);
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((address == null) ? 0 : address.hashCode());
        result = prime * result + ((firstName == null) ? 0 : firstName.hashCode());
        result = prime * result + id;
        result = prime * result + ((lastName == null) ? 0 : lastName.hashCode());
        result = prime * result + number;
        result = prime * result + ((patients == null) ? 0 : patients.hashCode());
        result = prime * result + ((specialization == null) ? 0 : specialization.hashCode());
        result = prime * result + ((visits == null) ? 0 : visits.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        Dentist other = (Dentist) obj;
        if (address == null) {
            if (other.address != null)
                return false;
        } else if (!address.equals(other.address))
            return false;
        if (firstName == null) {
            if (other.firstName != null)
                return false;
        } else if (!firstName.equals(other.firstName))
            return false;
        if (id != other.id)
            return false;
        if (lastName == null) {
            if (other.lastName != null)
                return false;
        } else if (!lastName.equals(other.lastName))
            return false;
        if (number != other.number)
            return false;
        if (patients == null) {
            if (other.patients != null)
                return false;
        } else if (!patients.equals(other.patients))
            return false;
        if (specialization == null) {
            if (other.specialization != null)
                return false;
        } else if (!specialization.equals(other.specialization))
            return false;
        if (visits == null) {
            if (other.visits != null)
                return false;
        } else if (!visits.equals(other.visits))
            return false;
        return true;
    }

}

@Entity
@Table(name="wizyta")
public class Visit implements Serializable {

    private static final long serialVersionUID = -135088128548004469L;

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private int id;

    @Column
    private String day;

    @Column
    private String time;

    @ManyToMany(cascade={CascadeType.DETACH,CascadeType.PERSIST,CascadeType.REFRESH,CascadeType.MERGE}, fetch=FetchType.EAGER)
    private List<Dentist>dentists;

    public Visit() {}

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getDay() {
        return day;
    }

    public void setDay(String day) {
        this.day = day;
    }

    public String getTime() {
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }

    public List<Dentist> getDentists() {
        return dentists;
    }

    public void setDentists(List<Dentist> dentists) {
        this.dentists = dentists;
    }

    @Override
    public String toString() {
        return "Visit [id=" + id + ", day=" + day + ", time=" + time +"]";
    }


    public void addDentist(Dentist dentist)
    {
        if(dentists==null)
        {
            dentists=new ArrayList<>();
        }
        dentists.add(dentist);
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((day == null) ? 0 : day.hashCode());
        result = prime * result + ((dentists == null) ? 0 : dentists.hashCode());
        result = prime * result + id;
        result = prime * result + ((time == null) ? 0 : time.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        Visit other = (Visit) obj;
        if (day == null) {
            if (other.day != null)
                return false;
        } else if (!day.equals(other.day))
            return false;
        if (dentists == null) {
            if (other.dentists != null)
                return false;
        } else if (!dentists.equals(other.dentists))
            return false;
        if (id != other.id)
            return false;
        if (time == null) {
            if (other.time != null)
                return false;
        } else if (!time.equals(other.time))
            return false;
        return true;
    }   
}

谢谢你的帮助!

共有1个答案

哈沛
2023-03-14

不能对标识符字段(int、long等)使用原语。创建新实体的过程,例如访问:

>

  • 创建新对象:Visit access=new Visit()(用基元int访问的id字段填充0

    如果id不是null,MySQL的策略IDENTITY将自动增加id,并且它将是1

    填充下一个字段

    第二次访问对象:

    >

  • 创建新对象...它的id字段将再次为0

    策略IDENTITY自动递增,它将再次成为1

    如果设置了唯一标志,则在创建第二个对象时会出现异常。使用Long、Integer、String或其他类型字段作为标识符(对于所有字段,最好使用非基本类型,因为创建实体时始终没有参数构造函数)。

  •  类似资料:
    • 问题内容: 我有3个具有ManyToMany关系的实体: 角色实体: 权限实体: 功能实体: 我做了以下事情: 我创建了3个功能: 然后创建2个权限: Permission2 with Functionality2, Functionality3 然后创建一个角色: 我收到以下异常: java.lang.IllegalStateException:同一实体[com.persistence.enti

    • 首先,我已经阅读了Hibernate——一个包含多个实体的表?。 然而,我希望将两个实体映射到同一个表,但我希望它们都是实体,我可以从中选择。我的意思是: 一个表:人(id、姓名、出生日期、城市、街道、邮政编码)。 两个实体:人(id、name、dateOfBirth)、地址(id、城市、街道、邮政编码)。 实体之间是1:1的关系,但数据库中仍然是1个表。 如果我在上面的链接中使用建议的解决方案(

    • 我得同时更新三张表。当我从邮递员点击时,所有表都成功保存了,但当我尝试更新时,它抛出了catch异常,就像同一个实体的多个表示一样。 EmployeeDetails InvalidDataAccessapiUsageException:正在合并同一实体[com.icore.payroll.attendance.entity.EmployeeDetails#379]的多个表示形式。已分离:[Empl

    • 当我映射同一个实体时,就像这里回答的那样: Hibernate与同一实体的多对多关联 在“tbl_friends”表中,我有相同含义的行。例如,我有id=1的用户和id=2的用户。在“tbl_friends”表中,当他们作为朋友链接时,我有两行 使用Hibernate或JPA引用是否可以在一行(1-2或2-1)中建立这种关系?

    • 问题内容: 假设我有一个包含200列的表格,其中大多数从未使用过。 我将SmallEntity映射到经常使用的10列。我在与其他实体的关联中使用它。它加载速度快,消耗很少的内存,让我很高兴。 但是有时我需要显示200列。我想在200列上映射BigEntity类。它没有绑定到其他实体,也没有关联。 问题:您有这样做的经验吗?您是否知道Hibernate可能会遇到的任何麻烦,例如在一级缓存,脏检查和实

    • 我必须将属于多个实体的数据存储在一个集合中。但是当我查询然后返回时,我不希望结果中出现不需要的记录。我们如何使用Spring实现这一点?以下是我迄今为止所做的。 1.我在实体中给出相同的集合名称,如下所示。 2、我创建独立的mongoRepository接口 3.问题是 当我做animalRepo的时候。芬德尔或humanRepo。芬德尔,我收集了所有的记录。 4.我所期望的 AnimalRepo