Hibernate Query Language (HQL) QueryException: не удалось разрешить свойство: Транзакции: classes.Advicenote, как я могу решить эту проблему?я сбит с толку - PullRequest
0 голосов
/ 19 февраля 2019

Herre - диаграмма отношения-смежности таблиц моей базы данных

Advicenote Переменная In_Or_Out таблицы указывает, поступают ли товары из компании, а какие поступают, Транзакции имеет переменную потока, которая фактически является количеством или количеством элементов, которые поступают или выходят из системы.Я хочу запросить фактическое количество предметов в инвентаре, умножив Advicenote.In_Or_Out и Transactions.Flow, затем суммирую их и сгруппирую по Items.Item_ID. Буду признателен за любую помощь!

Ниже вы можете увидеть HQL, который я написал для этой цели, и сообщение об ошибке, которое я получаю:

public List<ItemAndQuantity> getQuantity()
        {
        List<ItemAndQuantity> quantity = new ArrayList<ItemAndQuantity>();



            try {
                session = sessionFactory.openSession();
                transaction = session.beginTransaction();
                Query query = session.createQuery("select sum(t.flow * a.inOrOut) from Advicenote a join a.Transactions t join t.Items i group by i.itemId");
                quantity = query.list();
                transaction.commit();
            } 
        catch (HibernateException e) {
            if (transaction != null) {
                transaction.rollback();
            }
        }
        finally {
             session.close();}
             return quantity;
        }

Исключение в потоке "AWT-EventQueue-0" java.lang.IllegalArgumentException: org.hibernate.QueryException: не удалось разрешить свойство: Транзакции: classes.Advicenote [выберите сумму (t.flow * a.inOrOut) из классов.Выступать с предложением a.Transaction t присоединиться к t.Items i group по i.itemId] в org.hibernate.internal.ExceptionConverterImpl.convert (ExceptionConverterImpl.java:138) в org.hibernate.internal.ExceptionConverterImpl.convert (ExceptionConjavaterImpl181) в org.hibernate.internal.ExceptionConverterImpl.convert (ExceptionConverterImpl.java:188) в org.hibernate.internal.AbstractSharedSessionContract.createQuery (AbstractSharedSessionContract.java:713Aj.jmpl.: 23) на stock.view.StockView.getQuantity (StockView.java:145) на stock.view.StockView.FillData (StockView.java:62) в stock.view.StockView. (StockView.java:38) в main.view.MainMenu.stockMenuItemActionPerformed (MainMenu.java:290) в main.view.MainMenu $ FormListener.actionPerformed (MainMenu.java:240) в java.desktop / javax.swing.AbstractButton.fireActionPerformed (AbstractButton.java:1967) в java.desktop / javax.swing.AbstractButton $ Handler.actionPerformed (AbstractButton.java:230k) в/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405) в java.desktop / javax.swing.DefaultButtonModel.setPressed (DefaultButtonModel.java:262) в java.desktop / javbut.jpg369) в java.desktop / java.awt.AWTEventMulticaster.mouseReleased (AWTEventMulticaster.java:297) в java.desktop / java.awt.Component.processMouseEvent (Component.java:6632) в java.desktop / javax.swing.JComponent.processMouseEvent (JComponent.java:3342) в java.desktop / java.awt.Component.processEvent (Component.java:6397) в java.desktop / java.awt.Container.processEvent (Container.java:2263) в java.desktop / java.awt.Component.dispatchEventImpl (Component.java:5008) в java.desktop / java.awt.Container.dispatchEventImpl (Container.java:21) в java.desktop / java.awt.Component.dispatchEvent (Component.java:4840) в java.desktop / java.awt.LightweightDispatcher.retargetMouseEvent (Container.java:4918) в java.desktop / java.awt.LightweightDispat.processMouseEvent (Container.java:4547) в java.desktop / java.awt.LightweightDispatcher.dispatchEvent (Container.java:4488) в java.desktop / java.awt.Container.dispatchEventImpl (Container.java:2307k) в java./java.awt.Window.dispatchEventImpl(Window.java:2772) в java.desktop / java.awt.Component.dispatchEvent (Component.java:4840) в java.desktop / java.awt.EventQueue.dispatchEventImpjQ (событие: 772) в Яве.desktop / java.awt.EventQueue $ 4.run (EventQueue.java:721) в java.desktop / java.awt.EventQueue $ 4.run (EventQueue.java:715) в java.base / java.security.AccessController.doPrivileged(Родной метод) вjava.base / java.security.ProtectionDomain.EventQueue $ 5.run (EventQueue.java:745) в java.desktop / java.awt.EventQueue $ 5.run (EventQueue.java:743) в java.base / java.security.AccessController.doPrivileged (собственный метод) в java.base / java.security.ProtectionDomain $ JavaSecurityAccessImpl.doIntersectionPrivilege (ProtectionDomain.java:85) в java.desktop / java.awt.EventQueue.dispatchEvent (EventQueue.java:742) в java.desktop / jvent.Forp.EventDispatchThread.java:203) в java.desktop / java.awt.EventDispatchThread.pumpEventsForFilter (EventDispatchThread.java:124) в java.desktop / java.awt.EventDispatchThread.pavaEventsForHierarchkjjjjjjjjistop.awt.EventDispatchThread.pumpEvents (EventDispatchThread.java:109) в java.desktop / java.awt.EventDispatchThread.pumpEvents (EventDispatchThread.java:101) в java.desktop / java.awt.EventDispatchThread.run (EventDispatchThread.java:90), вызванный: свойство org.hibernate.QueryException: Транзакции: classes.Advicenote [выберите сумму (t.flow * a.inOrOut) из classes.Advicenote a join a.Транзакции t присоедините t.Ims элементы, которые я сгруппировал по i.itemId] в org.hibernate.QueryException.generateQueryException (QueryException.java: 120) в org.hibernate.QueryException.wrapWithQueryString (QueryException.java:103) в org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile (QueryTranslatorImpl.java:220) в org.hiber.ast.QueryTranslatorImpl.compile (QueryTranslatorImpl.java:144) в org.hibernate.engine.query.spi.HQLQueryPlan. (HQLQueryPlan.java:118) в org.hibernate.engine.query.spi.HQLQujPlan:78) в org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan (QueryPlanCache.java:158) в org.hibernate.internal.AbstractSharedSessionContract.getQueryPlan (AbstractSharedSessionContract.java:595) в org.hibernate.internal.AbstractSharedSessionContract.createQuery (AbstractSharedSessionContract.java:704) ... еще 44 Причина: свойство org.hibernate.QueryException: не удалось разрешить: не удалось разрешить свойства: не удалось разрешить.Advicenote в org.hibernate.persister.entity.AbstractPropertyMapping.propertyException (AbstractPropertyMapping.java:73) в org.hibernate.persister.entity.AbstractPropertyMapping.toType (AbstractPropertyMapping.java:67nate.Aers.Antister.iber..toType (AbstractEntityPersister.java:1983) в org.hibernate.hql.internal.ast.tree.FromElementType.getPropertyType (FromElementType.java:396) в org.hibernate.hql.internal.ast.tree.FromElement.java: 515) в org.hibernate.hql.internal.ast.tree.DotNode.getDataType (DotNode.java:686) в org.hibernate.hql.internal.ast.tree.DotNode.prepareLhs (DotNode.java:264).) в org.hibernate.hql.internal.ast.tree.DotNode.resolve (DotNode.java:204) в org.hibernate.hql.internal.ast.tree.FromReferenceNode.resolve (FromReferenceNode.java:114) в org.hibernate.hql.internal.ast.tree.FromReferenceNode.resolve (FromReferenceNode.java:109) в орг..hibernate..HqlSqlBaseWalker.fromElement (HqlSqlBaseWalker.java:3706) по адресу org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElementList (HqlSqlBaseWalker.java:3584.lq.lq: 720) в org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query (HqlSqlBaseWalker.java:576) вorg.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement (HqlSqlBaseWalker.java:313) в org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement (HqlSqlternal.alh.hlh.hlh.hl).ast.QueryTranslatorImpl.analyze (QueryTranslatorImpl.java:272) в org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile (QueryTranslatorImpl.java:192) ... еще 50

* 1019являются затронутыми классами и сопоставлениями XML: Advicenote
package classes;

        import java.util.Date;
        import java.util.Set;

        public class Advicenote  implements java.io.Serializable {


             private int advicenoteId;
             private Short inOrOut;
             private Date advicedate;
             private Partner partner;
             private Set<Transactions> transactions;

            public Advicenote() {
            }

            public Advicenote(int advicenoteId, Short inOrOut, Date advicedate, Partner partner, Set<Transactions> transactions) {
                this.advicenoteId = advicenoteId;
                this.inOrOut = inOrOut;
                this.advicedate = advicedate;
                this.partner = partner;
                this.transactions = transactions;
            }


            public int getAdvicenoteId() {
                return this.advicenoteId;
            }

            public void setAdvicenoteId(int advicenoteId) {
                this.advicenoteId = advicenoteId;
            }

            public Date getAdvicedate() {
                return advicedate;
            }

            public void setAdvicedate(Date advicedate) {
                this.advicedate = advicedate;
            }

                public Short getInOrOut() {
                return this.inOrOut;
            }

            public void setInOrOut(Short inOrOut) {
                this.inOrOut = inOrOut;
            }

            public Partner getPartner() {
                return partner;
            }

            public void setPartner(Partner partner) {
                this.partner = partner;
            }


            public Set<Transactions> getTransactions() {
                return transactions;
            }

            public void setTransactions(Set<Transactions> transactions) {
                this.transactions = transactions;
            }


        }

Advicenote XML

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<!-- Generated Feb 9, 2019, 3:57:52 PM by Hibernate Tools 4.3.1 -->
<hibernate-mapping>
    <class name="classes.Advicenote" table="ADVICENOTE" schema="APP" optimistic-lock="version">
        <id name="advicenoteId" type="int" column="ADVICENOTE_ID">
            <generator class="native" />
        </id>
        <property name="advicedate" type="date" column="ADVICE_DATE" length="10" />
        <property name="inOrOut" type="java.lang.Short" column="IN_OR_OUT" />
        <many-to-one 
            name="partner" class="classes.Partner"/>  
        <set name="transactions" table="TRANSACTIONS" inverse="false" cascade="all" lazy="true" fetch="select">       
            <key column="ADVICENOTE_ID" not-null="true"/>
            <one-to-many class="classes.Transactions"/>
        </set>
    </class>
</hibernate-mapping>

Класс транзакций:

package classes;

public class Transactions  implements java.io.Serializable {


     private int transactionsId;
     private int flow;
     private Integer netPrice;
     private Advicenote advicenote;
     private Items item;

    public Transactions() {
    }

    public Transactions(int transactionsId, int flow, Integer netPrice, Advicenote advicenote, Items item) {
        this.transactionsId = transactionsId;
        this.flow = flow;
        this.netPrice = netPrice;
        this.advicenote = advicenote;
        this.item = item;
    }

    public int getTransactionsId() {
        return this.transactionsId;
    }

    public void setTransactionsId(int transactionsId) {
        this.transactionsId = transactionsId;
    }

    public int getFlow() {
        return this.flow;
    }

    public void setFlow(int flow) {
        this.flow = flow;
    }

    public Integer getNetPrice() {
        return this.netPrice;
    }

    public void setNetPrice(Integer netPrice) {
        this.netPrice = netPrice;
    }

    public Advicenote getAdvicenote() {
        return advicenote;
    }

    public void setAdvicenote(Advicenote advicenote) {
        this.advicenote = advicenote;
    } 

    public Items getItem() {
        return item;
    }

    public void setItem(Items item) {
        this.item = item;
    }


}

Транзакции XML

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<!-- Generated Feb 9, 2019, 3:57:52 PM by Hibernate Tools 4.3.1 -->
<hibernate-mapping>
    <class name="classes.Transactions" table="TRANSACTIONS" schema="APP" optimistic-lock="version">
        <id name="transactionsId" type="int" column="TRANSACTIONS_ID">
            <generator class="native" />
        </id>
        <property name="flow" type="int" column="FLOW" not-null="true" />
        <property name="netPrice" type="java.lang.Integer" column="NET_PRICE" />

        <many-to-one name="advicenote" class="classes.Advicenote"/>
        <many-to-one name="item" class="classes.Items" fetch="select" cascade="save-update" column="ITEM_ID" unique="true" not-null="true"/>
    </class>
</hibernate-mapping>

Элементы

package classes;

public class Items  implements java.io.Serializable {


     private int itemId;
     private String name;
     private Integer netPrice;
     private Integer vatRate;
     private Categories category;
     //has-a relationship


    public Items() {
    }

    public Items(int itemId, String name, Integer netPrice, Integer vatRate, Categories category) {
        this.itemId = itemId;
        this.name = name;
        this.netPrice = netPrice;
        this.vatRate = vatRate;
        this.category = category;
    }

    public int getItemId() {
        return this.itemId;
    }

    public void setItemId(int itemId) {
        this.itemId = itemId;
    }
    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getNetPrice() {
        return this.netPrice;
    }

    public void setNetPrice(Integer netPrice) {
        this.netPrice = netPrice;
    }
    public Integer getVatRate() {
        return this.vatRate;
    }

    public void setVatRate(Integer vatRate) {
        this.vatRate = vatRate;
    }

    public Categories getCategory() {
        return category;
    }

    public void setCategory(Categories category) {
        this.category = category;
    }


}

Элементы XML

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="classes.Items" table="ITEMS" schema="APP" optimistic-lock="version">
        <id name="itemId" type="int" column="ITEM_ID">
            <generator class="native" />
        </id>
        <property name="name" type="string" column="NAME" length="100"/>
        <property name="netPrice" type="java.lang.Integer" column="NET_PRICE"/>
        <property name="vatRate" type="java.lang.Integer" column="VAT_RATE"/>
        <many-to-one name="category" class="classes.Categories" fetch="select" column="CATEGORY_ID" not-null="true"/>
    </class>
</hibernate-mapping>

Категории XML

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<!-- Generated Feb 9, 2019, 3:57:52 PM by Hibernate Tools 4.3.1 -->
<hibernate-mapping>
    <class name="classes.Categories" table="CATEGORIES" schema="APP" optimistic-lock="version">
        <id name="categoryId" type="int">
            <column name="CATEGORY_ID" />
            <generator class="native" />
        </id>
        <property name="name" type="string">
            <column name="NAME" length="100" />
        </property>
     <set name="items" table="ITEMS" inverse="false" cascade="all" lazy="false" fetch="select">
        <key>
            <column name="CATEGORY_ID" not-null="true" />
        </key>
        <one-to-many class="classes.Items" />
    </set>
    </class>
</hibernate-mapping>

Ответы [ 2 ]

0 голосов
/ 19 февраля 2019

Ваш запрос:

select sum(t.flow * a.inOrOut) from Advicenote a join a.Transactions t join t.Items i group by i.itemId

должен быть:

select sum(t.flow * a.inOrOut) from Advicenote a join a.transactions t join t.item i group by i.itemId

(transactions в нижнем регистре и item также в нижнем регистре и без 's').Они относятся к полям, а не к классам.

0 голосов
/ 19 февраля 2019

Проблема с «a.Transactions» также удалить. Элементы Используйте это: -

select sum(t.flow * a.inOrOut) from Advicenote a join Transactions t join Items i group by i.itemId
...