Cast « Query « JPA Q&A





1. cast(val as char) in hibernate config named query    stackoverflow.com

I am facing data truncation issue with hibernate for DB2 Char datatype. I am getting only the first character for DB2 char datatype using hibernate. I looked through the net and got two ...

2. Hibernate Criteria query - Class cast exception    stackoverflow.com

I am using Hibernate(3.2) Criteria for querying and its giving me exception when converting to a list. Please see my code and exception below:

    List<Summary> summaryList;
    ...

3. Trying to get distinct results, saying string cannot be cast to blah.Model.Article    stackoverflow.com

Trying to get all articles, with unique titles (distinct(title)), that have a body of "".

List<Article> articles = (List<Article>) session.createQuery("select distinct a.title from Article a where body = :body")
.setString("body", "")
.list();
I am getting ...

4. Entities cannot be cast to java.lang.Double    stackoverflow.com

  public static List<Transaction1> debitSourceAccBalance (Integer youraccinput, Integer toaccinput, String recname, Double amtsender) {
    EntityManager em = emf.createEntityManager();
    em.getTransaction().begin();
    Query q ...

5. Specifying columns in jpql select causes casting error    stackoverflow.com

When I specify columns in my jpql/jpa 2.0 query, i.e. select p.id, p.lastName, p.firstName from Profile p where p.group = :group I get the following error: [Ljava.lang.Object; cannot be cast to ...

6. JPA native query join returns object but dereference throws class cast exception    stackoverflow.com

I'm using JPQL Native query to join table and query result is stored in List<Object[]>.

public String getJoinJpqlNativeQuery() {



            String final ...

7. How do I write hql query with cast?    stackoverflow.com

I need to combine 2 tables using hql, both are having common column, but table1 common column is integer and table2 common column is String For example,

select a.id as id,a.name as name,b.address ...

8. Problems downcasting a hibernate query    stackoverflow.com

I'm handling a problem in downcasting a query.uniqueResult() using hibernate. I have 2 classes: - UserBean - UserLogin In the first one I have the mapping of all my table fields as well as ...

9. problem with openjpa query cache in glassfish + class cast exception form QueryKey    stackoverflow.com

Using openjpa 1.2.0 with it's built-in DataCache on Glassfish, enabling query cache and pin some named queires, We see the following exception: org.apache.openjpa.persistence.PersistenceException: java.lang.String cannot be cast to org.apache.openjpa.datacache.QueryKey Anyone has any ideas? Full ...





10. How can i access values returned by Hibernate Query?    stackoverflow.com

How can i access the elements from the list created as below? I tried creating a class containing a String and an int and cast to it but it doesn't work.

 ...

11. What is Hibernate equivalent of Projections.Cast?    stackoverflow.com

I have fixed my problem using HQL and it is working great. But I do like Criteria API. (I have a few ifs statements in my querybuilder string for HQL, yuck) ...

12. Casting result of HQL query    coderanch.com

Hi to @ll, I'm posting my trouble after surfing in browsers searching about types conversion and casting... I had worked queries in hibernate using Criteria API, now I need to use HQL. When I used Criteria, I set result list to my plain class using: criteria.createCriteria(myclass.class), but I've tried to cast the result of query.list() to a myclass array through a ...

13. can't cast the first element of an Object[] to String -- results of Hibernate Native SQL query    coderanch.com

So I have the following snippet java.util.List results = null; Object[] result; ListIterator mi = null; String sqlcmd; sqlcmd = "SELECT uu.code, " + " uu.rank, " + " uu.name, " + " uu.gender " + " FROM Employees AS uu "; SQLQuery hqlQuery = this.sessB.createSQLQuery(sqlcmd); // native SQL results = hqlQuery.list(); mi = results.listIterator(); while( mi.hasNext()) { result = mi.next(); ...

14. Casting in a JPA query    forum.hibernate.org

15. HQL queries with "select null as ", cast(integer as string)    forum.hibernate.org

I have beans being populated using constructor based queries as follows. session.createQuery("select new someBean(someProp1 as abc, someProp2 as bcd, null as cde, someProp3 as cde) from someEntity ").list(); Why should this throws a null pointer exception? The DB2 database does not seem to support the following: "select (cast(integerProp as string)) from someEntity" This casting should be database specific, but where do ...

16. class cast exception in find method - unusual    forum.hibernate.org

Hi We are getting the following exception, when we try to fetch data using Query.list. Some scenario we are getting on instance of PersistentSet , but expected is an implementation of List due to which, getting class cast exception. Version of Hibernate 3.2. it would be great if some help to resolve this issue. java.lang.ClassCastException: org.hibernate.collection.PersistentSet cannot be cast to java.util.List ...





17. can't cast first element returned by native SQL query    forum.hibernate.org

So I have the following snippet Code: java.util.List results = null; Object[] result; ListIterator mi = null; String sqlcmd; ...

18. how to query selected columns and cast it to right datatype    forum.hibernate.org

Sorry, i don't understand what you exactly want me to do. What is that devInfo.serialNumber and devInfo.CleanSerialNumber that you are refering to? Also, you are assigning it to object[]. I am getting an object[] back from the query. I need to extract the values of the object[] and assign it to either string[] or to individual string variables. What you are ...

19. Using SQL 'CAST' in 'order-by' for set's    forum.hibernate.org

Hibernate version: 2.1.7 MySQL 4.1.7-Max-log Hi There I have scoured the net in search of an answer to my question and came up empty handed so if someone could help me out that would be great: I would like to use the SQL 'CAST' function for the 'order-by' option of a hibernate 'set' mapping:

21. Using cast in order by    forum.hibernate.org

22. Casting from Hibernate query Object to custom class object    forum.hibernate.org

Hibernate version: 3.1 Name and version of the database you are using: MySQL 5 Hi, I have 2 tables (Owners, Cats) on my DB, both mapped with MyEclipse Hibernate support. This DAO works very well and returns all the owners: public Owners[] getAllOwners() { List ownersList = new ArrayList(); //Open communication with DB Session session = HibernateSessionFactory.currentSession(); Transaction tx = session.beginTransaction(); ...

23. Iterating & casting after query    forum.hibernate.org

Hibernate 3.1 beta 3 JBoss 4.0.3 I am having trouble while iterating over a List of results. I get a ClassCastException when I try to cast the proxy to User. Type found in the collection is com.monkeyden.pipeline.poc.bo.User$$EnhancerByCGLIB$$646a18c4 Code: Query query = session.createQuery("from com.monkeyden.pipeline.poc.bo.User u where " + ...

24. Help casting query object HQL    forum.hibernate.org

I have a HQL query where i select the column from different tables. I have a problem casting the query object. Can some one tell how to iterate over this query object and get the individual columns. sql.append(" select contract.organization.name, contract.organization.orgLevel, contractseason.season.name,") .append(" contractseason.contractStatus, contractproduct.products.name ") .append(" from ContractSeason contractseason join contractseason.organizationContracts contract " ) .append(" join contractseason.contractprod contractproduct "); Query ...

25. Class Casting Exception with Hibernate Named Queries    forum.hibernate.org

Hi, I tried with the hibernate named queries, it is working fine if i use one single table to retrive the data. If i use more than table to compare and get the query result it is returning the general java.lang.object. So, i tried casting the general to the specific class which i need but that object returns the combination of ...

26. Order by and casting with Criteria    forum.hibernate.org

27. class cast exception while iterating hql query result    forum.hibernate.org

It's obvious that the results are coming from your two POJOs Company and Founder but you only get two properties. So I think you get an array with two Strings. To check that log the type of each element that is in your idList. If it is an array iterate the array and log the type of each field. Then check ...