Hibernate参考手册中的例子谁跑过?

03-09-07 anonymous
Hibernate参考手册中的例子谁跑过?

Chapter 10. A Worked Example

关于一个简单Blog的程序,我在跑的时候出现几个问题,请教:

1:BlogMail中的listAllBlogNamesAndItemCounts()方法返回的是List

对象

但我在取其数据时报错:

Hibernate: select blog0_.ID as x0_0_, blog0_.Name as x1_0_,

count(items1_.ID) as x2_0_ from Blog blog0_ left outer join

BlogItem items1_ on blog0_.ID=items1_.Blog_ID group by

blog0_.Name , blog0_.ID order by max(items1_.DateTime) limit

?, ?

[WARN ] 2003-09-07 20:25:23

net.sf.hibernate.util.JDBCExceptionReporter - SQL Error: 1111,

SQLState: S1000

[ERROR] 2003-09-07 20:25:23

net.sf.hibernate.util.JDBCExceptionReporter - General error,

message from server: "Invalid use of group function"

[ERROR] 2003-09-07 20:25:23

net.sf.hibernate.util.JDBCExceptionReporter - Could not execute

query

java.sql.SQLException: General error, message from server:

"Invalid use of group function"

group错了嘛?代码是从参考手册中copy过来的,很奇怪

2:listBlogsAndRecentItems()方法

他的HQL:

Query q = session.createQuery("from Blog as blog "

+ "inner join blog.items as blogItem "

+ "where blogItem.datetime > :minDate");

我认为其返回的应该是Blog对象集合,但在程序中我用:

//Blog blog = (Blog)ls.get(i);

的时候抛出:ClassCastException,难道偶用错了?

3:关于lazy加载:

手册中设置的是lazy=“true”

但此时我用:

blog = (Blog) session.load(Blog.class, id);

取Blog时却出错,session过期,

将lazy设置成false后却可以

对lazy加载模块还不熟,高手可以指点一二嘛?

谢谢先:)

顺便问一下:有玩Blog的嘛?刚了解一点点,想知道的更多,特别时实

现技术:)

chinahero
2003-09-08 08:42
没看过这个例子,什么版本的hibernate?

anonymous
2003-09-08 09:09
2.0的,参考手册第十章:)

猜你喜欢