zhangyuanjun010
发贴: 3
积分: 0
|
于 2008-08-12 16:59
表1 create table TS_ITEM ( ID NUMBER(10) not null, ITEMNAME NVARCHAR2(120) not null, ITEMCODE NUMBER not null, ITEMPOPEDOM NUMBER not null ) alter table TS_ITEM add constraint DSJFLJSDAOIFJAJIF primary key (ID)
表2 -- Create table create table TS_SUBITEM ( ID NUMBER(10) not null, SUBNAME NVARCHAR2(120) not null, SUBCODE NUMBER not null, POPEDOM NUMBER not null, ITEM_ID NUMBER(10) not null ) alter table TS_SUBITEM add constraint IOJIOSAJHADF46546 primary key (ID) alter table TS_SUBITEM add constraint SJAFLKJSADLKFJI56465 foreign key (ITEM_ID) references TS_ITEM (ID);
表1.hbm.xml <class name="org.testZFXX.Item" table="TS_ITEM"> <id name="id" type="java.lang.Long"> <column name="ID" precision="10" scale="0" /> <generator class="incerment"></generator> </id> <property name="itemname" type="java.lang.String"> <column name="ITEMNAME" not-null="true" /> </property> <property name="itemcode" type="java.lang.Long"> <column name="ITEMCODE" precision="22" scale="0" not-null="true" /> </property> <property name="itempopedom" type="java.lang.Long"> <column name="ITEMPOPEDOM" precision="22" scale="0" not-null="true" /> </property> <set name="Subitems" inverse="true"> <key> <column name="ITEM_ID" precision="10" scale="0" not-null="true" /> </key> <one-to-many class="org.testZFXX.Subitem" /> </set> </class>
表2.hbm.xml <class name="org.testZFXX.Subitem" table="TS_SUBITEM"> <id name="id" type="java.lang.Long"> <column name="ID" precision="10" scale="0" /> <generator class="increment"></generator> </id> <many-to-one name="Item" class="org.testZFXX.Item" fetch="select"> <column name="ITEM_ID" precision="10" scale="0" not-null="true" /> </many-to-one> <property name="subname" type="java.lang.String"> <column name="SUBNAME" not-null="true" /> </property> <property name="subcode" type="java.lang.Long"> <column name="SUBCODE" precision="22" scale="0" not-null="true" /> </property> <property name="popedom" type="java.lang.Long"> <column name="POPEDOM" precision="22" scale="0" not-null="true" /> </property> </class>
表1 pojo public class Item { private long id; private String itemname; private long itemcode; private long itempopedom; private Set Subitems; ..................get,set................}
表2 pojo public class Subitem { private long id; private String subname; private long subcode; private long popedom; private Item item; ..................get,set................}
现在知道表1的一个itemcode为2000, 查表2中的item.itemcode=2000,且表2中popedom>=200的值
hql: from Subitem as a where a.popedom>=? and a.item.itemcode=?
报错: could not resolve property: item of: org.testZFXX.Subitem [from org.testZFXX.Subitem as a where a.popedom<=? and a.item.itemcode=? order by a.subcode] at org.hibernate.persister.entity.AbstractPropertyMapping.throwPropertyException(AbstractPropertyMapping.java:43) at org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:37) at org.hibernate.persister.entity.AbstractEntityPersister.toType(AbstractEntityPersister.java:1265) at org.hibernate.hql.ast.tree.FromElementType.getPropertyType(FromElementType.java:279) at org.hibernate.hql.ast.tree.FromElement.getPropertyType(FromElement.java:372) at org.hibernate.hql.ast.tree.DotNode.getDataType(DotNode.java:539) at org.hibernate.hql.ast.tree.DotNode.prepareLhs(DotNode.java:221) at org.hibernate.hql.ast.tree.DotNode.resolve(DotNode.java:172) at org.hibernate.hql.ast.tree.DotNode.resolveFirstChild(DotNode.java:139) at org.hibernate.hql.ast.HqlSqlWalker.lookupProperty(HqlSqlWalker.java:462) at org.hibernate.hql.antlr.HqlSqlBaseWalker.addrExpr(HqlSqlBaseWalker.java:4316) at org.hibernate.hql.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1211) at org.hibernate.hql.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:4032) ??????????????????
|