Results 1 to 4 of 4
  1. #1
    aliaj00 is offline Member
    Join Date
    Dec 2014
    Posts
    3
    Rep Power
    0

    Default newbie need help with query result in List

    Hi all,

    i am just restarting with java and i have an issue with this function in the APP.java i found this code on many examples on internet but for me is not working can someone help me find out what i am making wrog here :). PLEASE

    private static void read_D() {


    SessionFactory sf = HibernateUtil.getSessionFactory();
    Session session = sf.openSession();


    List list = session.createQuery("select employee_data.id, employee_data.datelindja, employee_data.muaji, employee_data.shenja_horoskopit from Employee_Data as employee_data where employee_data.datelindja is '24'and employee_data.viti is '1981' and employee_data.muaji is 'shtator' order by employee_data.id").list();

    System.out.println("Records Found ____ :");
    Iterator I = list.iterator();

    while (I.hasNext()) {

    Employee_Data emp = (Employee_Data) I.next();
    System.out.print("ID e rreshtit :" + emp.getId() + "datelindja :" + emp.getDatelindja() + "Muaji :" + emp.getViti() + "Viti :" + emp.getViti());

    }

    session.close();

    }

    error is:

    ic 10, 2014 11:39:47 AM org.hibernate.annotations.common.reflection.java.J avaReflectionManager <clinit>
    INFO: HCANN000001: Hibernate Commons Annotations {4.0.4.Final}
    dic 10, 2014 11:39:47 AM org.hibernate.Version logVersion
    INFO: HHH000412: Hibernate Core {4.3.5.Final}
    dic 10, 2014 11:39:47 AM org.hibernate.cfg.Environment <clinit>
    INFO: HHH000206: hibernate.properties not found
    dic 10, 2014 11:39:47 AM org.hibernate.cfg.Environment buildBytecodeProvider
    INFO: HHH000021: Bytecode provider name : javassist
    dic 10, 2014 11:39:47 AM org.hibernate.cfg.Configuration configure
    INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
    dic 10, 2014 11:39:47 AM org.hibernate.cfg.Configuration getConfigurationInputStream
    INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
    dic 10, 2014 11:39:48 AM org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity
    WARN: HHH000223: Recognized obsolete hibernate namespace Hibernate. Everything data. - Hibernate. Use namespace Directory listing /dtd - Hibernate instead. Refer to Hibernate 3.6 Migration Guide!
    dic 10, 2014 11:39:48 AM org.hibernate.cfg.Configuration addResource
    INFO: HHH000221: Reading mappings from resource: tmp/Employee.hbm.xml
    dic 10, 2014 11:39:48 AM org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity
    WARN: HHH000223: Recognized obsolete hibernate namespace Hibernate. Everything data. - Hibernate. Use namespace Directory listing /dtd - Hibernate instead. Refer to Hibernate 3.6 Migration Guide!
    dic 10, 2014 11:39:48 AM org.hibernate.cfg.Configuration addResource
    INFO: HHH000221: Reading mappings from resource: tmp/Employee_Data.hbm.xml
    dic 10, 2014 11:39:48 AM org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity
    WARN: HHH000223: Recognized obsolete hibernate namespace Hibernate. Everything data. - Hibernate. Use namespace Directory listing /dtd - Hibernate instead. Refer to Hibernate 3.6 Migration Guide!
    dic 10, 2014 11:39:48 AM org.hibernate.cfg.Configuration doConfigure
    INFO: HHH000041: Configured SessionFactory: null
    dic 10, 2014 11:39:49 AM org.hibernate.engine.jdbc.connections.internal.Dri verManagerConnectionProviderImpl configure
    WARN: HHH000402: Using Hibernate built-in connection pool (not for production use!)
    dic 10, 2014 11:39:49 AM org.hibernate.engine.jdbc.connections.internal.Dri verManagerConnectionProviderImpl buildCreator
    INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://192.168.10.240:3306/timitest1]
    dic 10, 2014 11:39:49 AM org.hibernate.engine.jdbc.connections.internal.Dri verManagerConnectionProviderImpl buildCreator
    INFO: HHH000046: Connection properties: {user=test, password=****}
    dic 10, 2014 11:39:49 AM org.hibernate.engine.jdbc.connections.internal.Dri verManagerConnectionProviderImpl buildCreator
    INFO: HHH000006: Autocommit mode: false
    dic 10, 2014 11:39:49 AM org.hibernate.engine.jdbc.connections.internal.Dri verManagerConnectionProviderImpl configure
    INFO: HHH000115: Hibernate connection pool size: 1 (min=1)
    dic 10, 2014 11:39:51 AM org.hibernate.dialect.Dialect <init>
    INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
    dic 10, 2014 11:39:51 AM org.hibernate.engine.jdbc.internal.LobCreatorBuild er useContextualLobCreation
    INFO: HHH000423: Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4
    dic 10, 2014 11:39:51 AM org.hibernate.engine.transaction.internal.Transact ionFactoryInitiator initiateService
    INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
    dic 10, 2014 11:39:51 AM org.hibernate.hql.internal.ast.ASTQueryTranslatorF actory <init>
    INFO: HHH000397: Using ASTQueryTranslatorFactory
    dic 10, 2014 11:39:52 AM org.hibernate.tool.hbm2ddl.SchemaValidator validate
    INFO: HHH000229: Running schema validator
    dic 10, 2014 11:39:52 AM org.hibernate.tool.hbm2ddl.SchemaValidator validate
    INFO: HHH000102: Fetching database metadata
    dic 10, 2014 11:39:53 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
    INFO: HHH000261: Table found: timitest1.employee
    dic 10, 2014 11:39:53 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
    INFO: HHH000037: Columns: [cell_phone, id, birth_date, lastname, firstname]
    dic 10, 2014 11:39:53 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
    INFO: HHH000261: Table found: timitest1.employee_data
    dic 10, 2014 11:39:53 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
    INFO: HHH000037: Columns: [id, shenja_horoskopit, viti, muaji, datelindja]
    Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to tmp.Employee_Data
    at tmp.APP.read_D(APP.java:218)
    at tmp.APP.main(APP.java:61)
    Records Found ____ :

  2. #2
    aliaj00 is offline Member
    Join Date
    Dec 2014
    Posts
    3
    Rep Power
    0

    Default Re: newbie need help with query result in List

    found it needed to remove the: <elect employee_data.id, employee_data.datelindja, employee_data.muaji, employee_data.shenja_horoskopit> from the query and leave in the query from the : <from Employee_Data as employee_data where employee_data.datelindja is '24'and employee_data.viti is '1981' and employee_data.muaji is 'shtator' order by employee_data.id">

    :P simple but got me 1 day to figure it out.

    Timi.

  3. #3
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,989
    Rep Power
    8

    Default Re: newbie need help with query result in List

    Did you actually understand what was wrong?

    Hibernate query != SQL
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  4. #4
    aliaj00 is offline Member
    Join Date
    Dec 2014
    Posts
    3
    Rep Power
    0

    Default Re: newbie need help with query result in List

    Quote Originally Posted by SurfMan View Post
    Did you actually understand what was wrong?

    Hibernate query != SQL
    :P Good point, and very good question. yep i noticed :P ;) . That query returned elements and i was expecting an object of type Employee_Data in my mind and the error was telling to my cluttered mind i cannot convert this elements to Employee_Data so change you code :P. or at least i think it was this :P. PLEASE correct me if i got it wrong.

    i am self studying and hitting walls after walls, and my head has so many scratches i don't recognize myself in the mirror aka IDE

    Timi.

Similar Threads

  1. where to put the result of query?
    By wiz6 in forum Java Servlet
    Replies: 2
    Last Post: 07-17-2013, 11:08 AM
  2. Using jTable to display query result
    By zenith666 in forum New To Java
    Replies: 2
    Last Post: 01-13-2012, 02:29 AM
  3. Replies: 1
    Last Post: 04-11-2011, 01:39 AM
  4. column result query
    By vikashkumar in forum JDBC
    Replies: 0
    Last Post: 04-03-2009, 02:23 PM
  5. Help!! how to turn query result to string
    By stefanybaez in forum Advanced Java
    Replies: 2
    Last Post: 12-11-2008, 11:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •