Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Database/JDBC/SQL/JDO/Hibernate » Oracle  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 hibernate 数据能保存,查询出问题了,在线等
zhangyuanjun010





发贴: 3
积分: 0
于 2008-08-12 16:59 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
表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)
??????????????????



作者 Re:hibernate 数据能保存,查询出问题了,在线等 [Re:zhangyuanjun010]
zhangyuanjun010





发贴: 3
积分: 0
于 2008-08-12 17:01 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
帮帮忙,我以前的系统都可以查,我新建的项目就不行,但我的数据都能加到表中,查Item也能查到


作者 Re:hibernate 数据能保存,查询出问题了,在线等 [Re:zhangyuanjun010]
zhangyuanjun010





发贴: 3
积分: 0
于 2008-08-12 17:15 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
有知道的吗,请教????



flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923