generate « Criteria « JPA Q&A





1. Criteria result set compared to generated SQL result set...    forum.hibernate.org

Hi. I'm using Criteria API to dynamically build query on Alert, User and UserReceivedAlert classes which are in many-to-many relationship. Relationship is modeled with 2 one-to-many many-to-one pairs. Here is the code for criteria : Code: Criteria ura = session.createCriteria(UserReceivedAlert.class); Criteria alert = ura.createCriteria("alert"); Criteria user = ura.createCriteria("user"); user.add(Restrictions.like("username", "somename")); ura.list(); When I run the generated sql separately from hibernate, result ...

2. Howto get SQL generated for Criteria?    forum.hibernate.org

Ok, I found a solution but its really ugly: Code: package khdb.util; import java.lang.reflect.*; import java.util.*; import java.util.Collections; import org.hibernate.*; import org.hibernate.engine.*; import org.hibernate.hql.*; import org.hibernate.hql.ast.*; import org.hibernate.impl.*; import org.hibernate.loader.*; import org.hibernate.loader.criteria.*; import org.hibernate.persister.entity.*; public class HibernateUtil { public static String toSql(Session session, Criteria criteria){ try{ ...

3. Criteria object generating erroneous SQL    forum.hibernate.org

i've been using the Criteria API quite successfully so far. but after a recent change in the model (one-to-one was changed to many-to-one due to the limitation in oracle to do primary key based association between 1..1 entities) the generated sql started to look something like this: Code: from deviceconfigurationversion this inner join managed_element x0_ on this.managedElement=x0_.id ...

4. Criteria object generating erroneous SQL    forum.hibernate.org

java.sql.SQLException: Invalid argument value, message from server: "Not unique table/alias: 'x0_'" at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1651) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:889) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:956) at com.mysql.jdbc.Connection.execSQL(Connection.java:1874) at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1538) at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:87) at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:795) at net.sf.hibernate.loader.Loader.doQuery(Loader.java:189) at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133) at ...

5. How to obtain underlying generated SQL from Criteria or HQL    forum.hibernate.org

All, I am using Hibernate 3.2 and for a certain use case i need access to the internal SQL generated from a Query Criteria Object. I am trying to add a filter tag to the generated HBMs and since the filter can take only SQL I need to obtain SQLs for the filtering criteria which the admins select from the provisioning ...

6. Generation of SQL or HQL from Criteria object    forum.hibernate.org