Thanks for your quiclk reply!
christian wrote:
Your code apparently executes two very simple SQL queries, how can that be slow? Have you checked the SQL log of Hibernate?
Yes, I have. The ResellerAgent has a many-to-one association to another object, which contains a collection and other stuff. The query I see hibernate issuing (left outer join) seems to indicate that it's reconstituting the whole object as well as eagerly reconstituting the object at the other end of the many-to-one. The log4j DEBUG messages from hibernate also indicate that Hibernate is doing far more than I need it to be doing for this purpose.
I tried doing a straight SQL query, but I was kind of guessing at it because I had a hard time understanding the doc chapter (15) on SQL queries. Or maybe the problem is that my SQL knowledge is too lame. Anyway, I guessed wrong because it didn't work... here's my code:
Code:
protected boolean existsWithKey (Object key)
throws HibernateException
{
net.sf.hibernate.Session hs = HibernateFactory.getSession();
String sql =
"select {agent.contactId} from ResellerAgent"
+ " where {agent.contactId} = :key";
Query q = hs.createSQLQuery (sql, "agent", ResellerAgent.class);
q.setLong ("key", ((Long)key).longValue());
return q.list().size() != 0;
}
...and here's what I see (I have hibernate.show_sql=true):
Code:
[java] Hibernate: select contactId0_ from ResellerAgent where contactId0_ = ?
[java] WARN - SQL Error: 1054, SQLState: S0022
[java] ERROR - Column not found, message from server: "Unknown column 'contactId0_' in 'field list'"
I think I'm just not grokking the table alias syntax for createSQLQuery() or something. Any ideas?
Quote:
I'm sure you can set indexes on any <column> mapping element.
Right! I found the relevant help on that here:
http://forum.hibernate.org/viewtopic.php?t=930488[/url]