gpt4 book ai didi

java - "org.hibernate.DuplicateMappingException: Duplicate query mapping"在 hibernate 中意味着什么

转载 作者:行者123 更新时间:2023-11-29 09:36:07 24 4
gpt4 key购买 nike

我正在尝试使用 hibernate 5.2.16 和 struts2-core-2.3.35 在带有 JDK8 的 Tomcat8.5 上运行 Spring Web 应用程序。

我收到以下异常:

Caused by: org.hibernate.DuplicateMappingException: Duplicate query mapping getDocExt
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.checkQueryName(InFlightMetadataCollectorImpl.java:524) ~[hibernate-core-5.2.16.Final.jar:5.2.16.Final]
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.applyNamedQuery(InFlightMetadataCollectorImpl.java:518) ~[hibernate-core-5.2.16.Final.jar:5.2.16.Final]
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.addNamedQuery(InFlightMetadataCollectorImpl.java:514) ~[hibernate-core-5.2.16.Final.jar:5.2.16.Final]
at org.hibernate.boot.model.source.internal.hbm.NamedQueryBinder.processNamedQuery(NamedQueryBinder.java:75) ~[hibernate-core-5.2.16.Final.jar:5.2.16.Final]
at org.hibernate.boot.model.source.internal.hbm.NamedQueryBinder.processNamedQuery(NamedQueryBinder.java:39) ~[hibernate-core-5.2.16.Final.jar:5.2.16.Final]
at org.hibernate.boot.model.source.internal.hbm.MappingDocument.processNamedQueries(MappingDocument.java:198) ~[hibernate-core-5.2.16.Final.jar:5.2.16.Final]
at org.hibernate.boot.model.source.internal.hbm.HbmMetadataSourceProcessorImpl.processNamedQueries(HbmMetadataSourceProcessorImpl.java:94) ~[hibernate-core-5.2.16.Final.jar:5.2.16.Final]
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess$1.processNamedQueries(MetadataBuildingProcess.java:173) ~[hibernate-core-5.2.16.Final.jar:5.2.16.Final]
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:269) ~[hibernate-core-5.2.16.Final.jar:5.2.16.Final]
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83) ~[hibernate-core-5.2.16.Final.jar:5.2.16.Final]
at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:418) ~[hibernate-core-5.2.16.Final.jar:5.2.16.Final]
at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:87) ~[hibernate-core-5.2.16.Final.jar:5.2.16.Final]
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:691) ~[hibernate-core-5.2.16.Final.jar:5.2.16.Final]
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:726) ~[hibernate-core-5.2.16.Final.jar:5.2.16.Final]
at org.springframework.orm.hibernate5.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:511) ~[spring-orm-4.3.15.RELEASE.jar:4.3.15.RELEASE]
at org.springframework.orm.hibernate5.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:495) ~[spring-orm-4.3.15.RELEASE.jar:4.3.15.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1688) ~[spring-beans-4.3.15.RELEASE.jar:4.3.15.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1626) ~[spring-beans-4.3.15.RELEASE.jar:4.3.15.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-4.3.15.RELEASE.jar:4.3.15.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.15.RELEASE.jar:4.3.15.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312) ~[spring-beans-4.3.15.RELEASE.jar:4.3.15.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.15.RELEASE.jar:4.3.15.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308) ~[spring-beans-4.3.15.RELEASE.jar:4.3.15.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.15.RELEASE.jar:4.3.15.RELEASE]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351) ~[spring-beans-4.3.15.RELEASE.jar:4.3.15.RELEASE]
... 24 more

当我查找此异常时,大多数答案都与

org.hibernate.DuplicateMappingException: Duplicate class/entity mapping

这是不同的,因为我得到的异常没有“重复的类/实体映射”。对我来说,它是“重复查询映射”。

出现此异常的原因可能是什么。

最佳答案

Caused by: org.hibernate.DuplicateMappingException: Duplicate query mapping getDocExt

堆栈跟踪中的这一行清楚地表明您不小心定义了两个 named queries同名 - getDocExt 。这两个具有相同名称的命名查询不一定必须位于同一实体上才会发生此错误。即使这些重复的命名查询在两个不同的实体上声明,您仍然会收到此错误。这是因为命名查询的范围是整个持久性单元。找出重复的命名查询并选择不同的名称。作为良好的编程习惯,请选择诸如 <entity>.getDocExt 之类的名称。而不仅仅是getDocExt 。如果您采用这种做法,您将永远不会出现此错误。

关于java - "org.hibernate.DuplicateMappingException: Duplicate query mapping"在 hibernate 中意味着什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57567510/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com