1

我正在使用Hibernate tools 3.3.Eclipse Indigo

有没有办法查看我创建的Sql等效查询?criteria

有一个视图Hibernate Dynamic SQL显示. 但我还没有找到任何预览。SqlHql editorcriteria

4

1 回答 1

0

使用 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>

只有在运行时才会生成 sqlcriteria.list()

   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!

请参阅使用 log4j 记录休眠 SQL

于 2013-05-05T15:03:09.240 回答