Java org.springframework.dao.InvalidDataAccessApiUsageException:同一实体的多个表示形式

Java org.springframework.dao.InvalidDataAccessApiUsageException:同一实体的多个表示形式,java,spring,hibernate,spring-mvc,Java,Spring,Hibernate,Spring Mvc,欢迎光临 我也看到过同样的问题,但解决方案对我没有帮助 当我尝试添加另一次牙医就诊时,问题就出现了。 我添加了hashCode和equals方法,但没有任何帮助。 从访问中删除cascadeType.MERGE也没有帮助。 我无法从牙医中删除cascadeType.MERGE,因为这样会出现另一个问题,即在将其添加到牙医之前必须存在该就诊 堆栈跟踪: org.springframework.web.util.NestedServletException: Request processing f

欢迎光临

我也看到过同样的问题,但解决方案对我没有帮助

当我尝试添加另一次牙医就诊时,问题就出现了。 我添加了hashCode和equals方法,但没有任何帮助。 从访问中删除cascadeType.MERGE也没有帮助。 我无法从牙医中删除cascadeType.MERGE,因为这样会出现另一个问题,即在将其添加到牙医之前必须存在该就诊

堆栈跟踪:

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;
    }   
}
@实体
@表(name=“dentysta”)
公共类实现可序列化{
私有静态最终长serialVersionUID=3128830699411486597L;
@身份证
@生成值
私有int-id;
@纵队
私有字符串名;
@纵队
私有字符串lastName;
@纵队
私有字符串专门化;
@纵队
私有整数;
@纵队
私有字符串地址;
@OneToMany(mappedBy=“dentor”,cascade={CascadeType.DETACH,CascadeType.MERGE,CascadeType.PERSIST,CascadeType.REFRESH},fetch=FetchType.EAGER)
私人病人名单;
@许多(mappedBy=“dentists”,cascade=CascadeType.ALL)
@LazyCollection(LazyCollectionOption.FALSE)
私人访问;
公共牙医(){
}
公共int getId(){
返回id;
}
公共无效集合id(内部id){
this.id=id;
}
公共字符串getFirstName(){
返回名字;
}
public void setFirstName(字符串firstName){
this.firstName=firstName;
}
公共字符串getLastName(){
返回姓氏;
}
public void setLastName(字符串lastName){
this.lastName=lastName;
}
公共字符串getSpecialization(){
回归专业化;
}
公共void集合专门化(字符串专门化){
专业化=专业化;
}
public int getNumber(){
返回号码;
}
公共无效集合号(整数){
这个数字=数字;
}
公共字符串getAddress(){
回信地址;
}
公共无效设置地址(字符串地址){
this.address=地址;
}
公众病人名单(){
返回病人;
}
公立医院病人(名单病人){
这是病人=病人;
}
公众名单{
回访;
}
公众访问(列表访问){
这个.访问量=访问量;
}
公共无效添加患者(患者)
{
System.out.println(“牙医=患者+加法器”);
如果(患者==null){
患者=新ArrayList();
}
病人。牙医(本);
患者。添加(患者);
}
公众参观(参观)
{
如果(访问次数==null)
{
访问次数=新建ArrayList();
}
看牙医(本);
访问。添加(访问);
}
@凌驾
公共int hashCode(){
最终整数素数=31;
int结果=1;
result=prime*result+((address==null)?0:address.hashCode();
result=prime*result+((firstName==null)?0:firstName.hashCode();
结果=素数*结果+id;
result=prime*result+((lastName==null)?0:lastName.hashCode();
结果=素数*结果+数字;
result=prime*result+((patients==null)?0:patients.hashCode();
result=prime*result+((专门化==null)?0:specialization.hashCode());
result=prime*result+((visions==null)?0:visions.hashCode());
返回结果;
}
@凌驾
公共布尔等于(对象obj){
if(this==obj)
返回true;
if(obj==null)
返回false;
如果(getClass()!=obj.getClass())
返回false;
牙医其他=(牙医)obj;
如果(地址==null){
if(other.address!=null)
返回false;
}如果(!address.equals(other.address))
返回false;
if(firstName==null){
if(other.firstName!=null)
返回false;
}else如果(!firstName.equals(other.firstName))
返回false;
if(id!=其他.id)
返回false;
if(lastName==null){
if(other.lastName!=null)
返回false;
}else如果(!lastName.equals(other.lastName))
返回false;
如果(编号!=其他.编号)
返回false;
如果(患者==null){
if(other.patients!=null)
返回false;
}如果(!patients.equals(other.patients))
返回false;
if(专门化==null){
if(other.specialization!=null)
返回false;
}else如果(!specialization.equals(other.specialization))
返回false;
如果(访问次数==null){
if(other.visions!=null)
返回false;
}如果(!visions.equals(其他访问))
返回false;
返回true;
}
}
@实体
@表(name=“wizyta”)
公共类访问实现了可序列化{
私有静态最终长serialVersionUID=-135088128548004469L;
@身份证
@GeneratedValue(策略=GenerationType.IDENTITY)
私有int-id;
@纵队
私人弦日;
@纵队
私有字符串时间;
@ManyToMany(cascade={CascadeType.DETACH,CascadeType.PERSIST,CascadeType.REFRESH,CascadeType.MERGE},fetch=FetchType.EAGER)
私人牙医;
公众访问(){}
公共int getId(){
返回id;
}
公共无效集合id(内部id){
this.id=id;
}
公共字符串getDay(){
回归日;
}
公共无效设置日(字符串日){
this.day=天;
}
公共字符串getTime(){
返回时间;
}
公共无效设置时间(字符串时间){
这个时间=时间;
}
公开名单(牙医){
返回