1

我们的 Maven 测试中有一个关键问题。我们收到错误:无法针对路径解析属性 [lieferungen]

不幸的是,其他帖子无法帮助我。

这是我的堆栈跟踪:

Running de.shop.bestellverwaltung.service.LieferverwaltungTest
Tests run: 4, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 36.446 sec <<< FAILURE!
createLieferung(de.shop.bestellverwaltung.service.LieferverwaltungTest)  Time elapsed: 0.079 sec  <<< ERROR!
java.lang.IllegalArgumentException: Unable to resolve attribute [lieferungen] against path
    at org.hibernate.ejb.criteria.path.AbstractPathImpl.unknownAttribute(AbstractPathImpl.java:120)
    at org.hibernate.ejb.criteria.path.AbstractPathImpl.locateAttribute(AbstractPathImpl.java:229)
    at org.hibernate.ejb.criteria.path.AbstractFromImpl.fetch(AbstractFromImpl.java:595)
    at de.shop.bestellverwaltung.dao.BestellungDao.findBestellungenByIds(BestellungDao.java:36)
    at de.shop.bestellverwaltung.dao.BestellungDao$Proxy$_$$_WeldSubclass.findBestellungenByIds(BestellungDao$Proxy$_$$_WeldSubclass.java)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.jboss.weld.interceptor.proxy.SimpleInterceptionChain.invokeNextInterceptor(SimpleInterceptionChain.java:84)
    at org.jboss.weld.interceptor.proxy.InterceptorInvocationContext.proceed(InterceptorInvocationContext.java:127)
    at de.shop.util.LogInterceptor.log(LogInterceptor.java:87)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.jboss.weld.interceptor.proxy.SimpleMethodInvocation.invoke(SimpleMethodInvocation.java:30)
    at org.jboss.weld.interceptor.proxy.SimpleInterceptionChain.invokeNextInterceptor(SimpleInterceptionChain.java:68)
    at org.jboss.weld.interceptor.proxy.InterceptorMethodHandler.executeInterception(InterceptorMethodHandler.java:112)
    at org.jboss.weld.interceptor.proxy.InterceptorMethodHandler.invoke(InterceptorMethodHandler.java:88)
    at org.jboss.weld.bean.proxy.CombinedInterceptorAndDecoratorStackMethodHandler.invoke(CombinedInterceptorAndDecoratorStackMethodHandler.java:53)
    at de.shop.bestellverwaltung.dao.BestellungDao$Proxy$_$$_WeldSubclass.findBestellungenByIds(BestellungDao$Proxy$_$$_WeldSubclass.java)
    at de.shop.bestellverwaltung.service.BestellverwaltungImpl.createLieferung(BestellverwaltungImpl.java:194)
    at de.shop.bestellverwaltung.service.BestellverwaltungImpl$Proxy$_$$_WeldSubclass.createLieferung(BestellverwaltungImpl$Proxy$_$$_WeldSubclass.java)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.jboss.weld.interceptor.proxy.SimpleInterceptionChain.invokeNextInterceptor(SimpleInterceptionChain.java:84)
    at org.jboss.weld.interceptor.proxy.InterceptorInvocationContext.proceed(InterceptorInvocationContext.java:127)
    at de.shop.util.LogInterceptor.log(LogInterceptor.java:87)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.jboss.weld.interceptor.proxy.SimpleMethodInvocation.invoke(SimpleMethodInvocation.java:30)
    at org.jboss.weld.interceptor.proxy.SimpleInterceptionChain.invokeNextInterceptor(SimpleInterceptionChain.java:68)
    at org.jboss.weld.interceptor.proxy.InterceptorMethodHandler.executeInterception(InterceptorMethodHandler.java:112)
    at org.jboss.weld.interceptor.proxy.InterceptorMethodHandler.invoke(InterceptorMethodHandler.java:88)
    at org.jboss.weld.bean.proxy.CombinedInterceptorAndDecoratorStackMethodHandler.invoke(CombinedInterceptorAndDecoratorStackMethodHandler.java:53)
    at de.shop.bestellverwaltung.service.BestellverwaltungImpl$Proxy$_$$_WeldSubclass.createLieferung(BestellverwaltungImpl$Proxy$_$$_WeldSubclass.java)
    at de.shop.bestellverwaltung.service.LieferverwaltungTest.createLieferung(LieferverwaltungTest.java:136)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
    at org.jboss.arquillian.junit.Arquillian$6$1.invoke(Arquillian.java:270)
    at org.jboss.arquillian.container.test.impl.execution.LocalTestExecuter.execute(LocalTestExecuter.java:60)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
    at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
    at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
    at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:135)
    at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:115)
    at org.jboss.arquillian.core.impl.EventImpl.fire(EventImpl.java:67)
    at org.jboss.arquillian.container.test.impl.execution.ContainerTestExecuter.execute(ContainerTestExecuter.java:38)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
    at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
    at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
    at org.jboss.arquillian.test.impl.TestContextHandler.createTestContext(TestContextHandler.java:89)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)

这些是我的域类(Lieferung):

public class Lieferung implements java.io.Serializable {
    private static final long serialVersionUID = -2297631209213102849L;

    private static final String PREFIX = "Lieferung.";
    public static final String FIND_LIEFERUNGEN_BY_LIEFERNR_FETCH_BESTELLUNGEN =
                               PREFIX + "findLieferungenByLieferNrFetchBestellungen";
    public static final String PARAM_LIEFERNR = "lieferNr";

    @Id
    @GeneratedValue
    @Column(name = "lid", unique = true, nullable = false, updatable = false, precision = LONG_ANZ_ZIFFERN)
    private Long lid;

    @Column(nullable = false)
    @Temporal(TIMESTAMP)
    private Date aktualisiert;

    @Column(nullable = false)
    @Temporal(TIMESTAMP)
    private Date erzeugt;

    @Column
    @Temporal(TIMESTAMP)
    private Date lieferungsdatum;

    @ManyToOne
    @JoinColumn(name = "bestellung_fk")
    private Bestellung bestellung;

这是我的域类 Bestellung:

public class Bestellung implements java.io.Serializable {
    private static final long serialVersionUID = -2703770025221749393L;

    private static final String PREFIX = "Bestellung.";
    public static final String FIND_BESTELLUNGEN_BY_KUNDE = PREFIX + "findBestellungenByKunde";
    public static final String FIND_BESTELLUNG_BY_ID_FETCH_LIEFERUNG =
                               PREFIX + "findBestellungenByIdFetchLieferung";
    public static final String FIND_KUNDE_BY_ID = PREFIX + "findBestellungKundeById";

    public static final String PARAM_KUNDEID = "kundeId";
    public static final String PARAM_ID = "id";

    @Id
    @GeneratedValue
    @Column(name = "bid", unique = true, nullable = false, updatable = false, precision = LONG_ANZ_ZIFFERN)
    @Min(value = MIN_ID, message = "{bestellverwaltung.bestellung.id.min}", groups = IdGroup.class)
    private Long bid = KEINE_ID;



    @OneToMany(fetch = EAGER, cascade = { PERSIST, REMOVE })
    @JoinColumn(name = "bid_fk", nullable = false)
    private List<Bestellposition> bestellpositionen;

    @OneToMany(cascade = { PERSIST, REMOVE }, mappedBy = "bestellung")
    private List<Lieferung> lieferung;

您还需要什么信息。我很绝望。在这里坐了大约4天。

4

1 回答 1

0

我在使用时看到了类似的错误select(root.get("COLUMN_NAME"))。最后,我必须使用 Hibernate JPA 2 Metamodel Generator 将元模型类生成到“目标/生成类/注释”中。maven-compiler-plugin你只需要添加一个依赖 jar 并再次构建,在我的情况下不需要玩。

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-jpamodelgen</artifactId>
            <version>${some_version_in_properties}</version>
        </dependency>

并且,为 IDE 启用注释处理,例如在 Intellij IDEA 中。

https://docs.jboss.org/hibernate/stable/jpamodelgen/reference/en-US/html_single/

名称以结尾的新类_ 将在类路径中。例如,对于实体类Entity,您将获得Entity_.class.

之后,您使用select(root.get(Entity_.propName))选择路径。

于 2021-09-08T13:53:25.200 回答