[英]Eclipse,Hibernate tools, Is there any way to preview the sql equivalent query for criteria editor
我正在Eclipse Indigo
使用Hibernate tools 3.3
。
有什么方法可以查看我創建的criteria
的Sql
等效查詢嗎?
一個Hibernate Dynamic SQL
視圖顯示了Hql editor
Sql
預覽。 但是我沒有找到任何criteria
預覽。
使用Hibernate Criteria API,查看SQL輸出的唯一方法是運行查詢。 沒有預覽。 為了查看生成的SQL,您必須配置數據源以記錄sql語句。 這是Hibernate MS SQLServer方言的persistence.xml示例。 =“ true”元素都是在運行Hibernate查詢時要冗長的說明。 不用說,這對性能有很大影響。
<persistence-unit name="projectPU" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>jdbc/projectDS</jta-data-source>
<properties>
<property name="hibernate.dialect"
value="org.hibernate.dialect.SQLServerDialect" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.use_sql_comments" value="true" />
</properties>
</persistence-unit>
僅當您運行criteria.list()
時才會生成sql
Criteria crit = session.createCriteria(Foo.class);
// create aliases and projections etc. whose effects are not visible yet
List<Foo> fooList = crit.list(); // only now can you see errors!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.