由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - Hibernate query
相关主题
请问hibernate这个功能如何实现?Desperately need help on DB2 connection through jdbc in jsp page
hibernate高手求助[转载] Question 1: refresh view of database?
find all tables used in a hibernate/jdbc project?arithmetic formula in java
急问hibernater queryArray of vector, help
hibernate问题。。求教 Listenser for table in Java
EHCache --- hibernate question[转载] 哪位先进用过MYSQL里面的LOCK TABLE
新手起步,找工作的问题How to get all tables in a schema in Oracle 9i using its JDBC driver?
请问各位(巨,大,中,小,微,不)牛java.lang.OutOfMemoryError: Java heap space in DB query
相关话题的讨论汇总
话题: query话题: table话题: hibernate话题: customer话题: when
进入Java版参与讨论
1 (共1页)
s*****p
发帖数: 5342
1
When I use hibernate, I found a problem. There are 4-5 tables which have one
-to-many in between. I have one object map to one table. The lowest and 2nd
lowest children level table have millions records. The top ones are just
hundreds at most. When I set search critia on both top and bottom level
table, the query is very slow. Something wrong with my implementation? Any
good suggestion?
3x!
f*******4
发帖数: 345
2
It seems you don't have to use projection at all, but you have to use left
outer join for sure.
The query could be like this:
select count(distinct s.id) from State s left join s.customer as c left join
c.purchases as p where c.gender="male" and p.item="pc" group by c.id having
count(p)>1000
If the query is really slow, you've to figure out some quirky way such as
adding a column into the state table as customer counter, and in your
business logic whenever a purchase happens, update the column
s*****p
发帖数: 5342
3
For your sample, I need add another table top on customer table, say state
for example. Assumely, one-to-many relationship is between state and
customer. It means one state has many customers. There is no relationship
between state and purchase.
Say, if I want to query how many states have male customer with pc purchases
over 1000, it seems hibernate use outer join to join all three tables and
return millions records with duplicated state name. If I use projection, it
is slow and also only retur

【在 f*******4 的大作中提到】
: It seems you don't have to use projection at all, but you have to use left
: outer join for sure.
: The query could be like this:
: select count(distinct s.id) from State s left join s.customer as c left join
: c.purchases as p where c.gender="male" and p.item="pc" group by c.id having
: count(p)>1000
: If the query is really slow, you've to figure out some quirky way such as
: adding a column into the state table as customer counter, and in your
: business logic whenever a purchase happens, update the column

f*******4
发帖数: 345
4
Can you post your code?
To simpily the question, say, you have a customer table which contains 100
rows,
each customer has thousands of purchases. the foreign key in customer table
is purchase_id which is the primary key of purchase table. What are your
mapping file and search query?
1 (共1页)
进入Java版参与讨论
相关主题
java.lang.OutOfMemoryError: Java heap space in DB queryhibernate问题。。
oracle help: pass array to oracle SPEHCache --- hibernate question
介绍个做web的framework吧!新手起步,找工作的问题
a prepared statement question请问各位(巨,大,中,小,微,不)牛
请问hibernate这个功能如何实现?Desperately need help on DB2 connection through jdbc in jsp page
hibernate高手求助[转载] Question 1: refresh view of database?
find all tables used in a hibernate/jdbc project?arithmetic formula in java
急问hibernater queryArray of vector, help
相关话题的讨论汇总
话题: query话题: table话题: hibernate话题: customer话题: when