Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8237131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:22:17+00:00 2026-06-07T19:22:17+00:00

I am facing a strange type cast error ( Compile Time Error ) As

  • 0

I am facing a strange type cast error ( Compile Time Error )
As soon as I retrieve the data from the journey table it throws following exception as it does not recognize the Object gotten from the list.

I don’t know why it is complaining like this, As the object, is already of journey type and I made a list of templatized with “Journey” type, every record is supposed to be journey.

"INFO: HHH000397: Using ASTQueryTranslatorFactory
Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to de.db.journeyTracker.model.journey
"

Code :

            public static void findalljourney(Session session )
    {

        String qryAllJourney = "SELECT j.id , j.operatingday, j.linename,  j.scheduledeparture, j.scheduledeparturestopname FROM journey j";

        Query query = session.createQuery(qryAllJourney);

        List<journey> allJourney;
        allJourney = query.list();                      

        for (int i = 0; i < allJourney.size(); i++) 
        {  

            String JourneyId =   allJourney.get(i).getJourneyid().toString(); /// TypeCast Exception Occured...
        }  

Following is the Model class for journey.

    public class journey 
{               
      int id ;
      String journeyid ;
      String linename ;
      Date operatingday ;
      Date realtimearrival;
      String  realtimearrivalstopname;
      String realtimearrivalstopnumber ;
      Date realtimedeparture ;
      String realtimedeparturestopname ;
      String realtimedeparturestopnumber;
      Date schedulearrival ;
      String schedulearrivalstopname ;
      String schedulearrivalstopnumber ;
      Date scheduledeparture ;
      String scheduledeparturestopname ;
      String  scheduledeparturestopnumber ;
      int arrivaldelay ;
      String direction ;
      String journeyoperator ;
      String schedulevehicletype ;
      String  vehicleid ;
      Double  distancerealtime;
      int  maximumspeedrealtime ;
      Boolean calledatallstops ;
      int departuredelay ;
      int maximumdelay; 
      int minimumdelay ;
      String phonenumber ;
      int comment_id ;
      Boolean arrivaldelayprojection ;
      Boolean  departuredelayprojection;
      Boolean maximumdelayprojection ;
      Boolean  maximumspeedrealtimedataincomplete;
      Boolean  minmaxdelaydataincomplete ;
      Boolean minimumdelayprojection ;
      Boolean realtimearrivalprojection ;
      Boolean  realtimedepartureprojection ;
       }

Following is hibernate config file corresponding to above journey model

<?xml version="1.0"?>
<hibernate-mapping>
    <class name="de.db.journeyTracker.model.journey" table="JOURNEY">
        <id name="id" type="int">
            <column name="ID" />
            <generator class="assigned" />
        </id>
        <property name="journeyid" type="java.lang.String">
            <column name="JOURNEYID" />
        </property>
        <property name="linename" type="java.lang.String">
            <column name="LINENAME" />
        </property>
        <property name="operatingday" type="java.util.Date">
            <column name="OPERATINGDAY" />
        </property>
        <property name="realtimearrival" type="java.util.Date">
            <column name="REALTIMEARRIVAL" />
        </property>
        <property name="realtimearrivalstopname" type="java.lang.String">
            <column name="REALTIMEARRIVALSTOPNAME" />
        </property>
        <property name="realtimearrivalstopnumber" type="java.lang.String">
            <column name="REALTIMEARRIVALSTOPNUMBER" />
        </property>
        <property name="realtimedeparture" type="java.util.Date">
            <column name="REALTIMEDEPARTURE" />
        </property>
        <property name="realtimedeparturestopname" type="java.lang.String">
            <column name="REALTIMEDEPARTURESTOPNAME" />
        </property>
        <property name="realtimedeparturestopnumber" type="java.lang.String">
            <column name="REALTIMEDEPARTURESTOPNUMBER" />
        </property>
        <property name="schedulearrival" type="java.util.Date">
            <column name="SCHEDULEARRIVAL" />
        </property>
        <property name="schedulearrivalstopname" type="java.lang.String">
            <column name="SCHEDULEARRIVALSTOPNAME" />
        </property>
        <property name="schedulearrivalstopnumber" type="java.lang.String">
            <column name="SCHEDULEARRIVALSTOPNUMBER" />
        </property>
        <property name="scheduledeparture" type="java.util.Date">
            <column name="SCHEDULEDEPARTURE" />
        </property>
        <property name="scheduledeparturestopname" type="java.lang.String">
            <column name="SCHEDULEDEPARTURESTOPNAME" />
        </property>
        <property name="scheduledeparturestopnumber" type="java.lang.String">
            <column name="SCHEDULEDEPARTURESTOPNUMBER" />
        </property>
        <property name="arrivaldelay" type="int">
            <column name="ARRIVALDELAY" />
        </property>
        <property name="direction" type="java.lang.String">
            <column name="DIRECTION" />
        </property>
        <property name="journeyoperator" type="java.lang.String">
            <column name="JOURNEYOPERATOR" />
        </property>
        <property name="schedulevehicletype" type="java.lang.String">
            <column name="SCHEDULEVEHICLETYPE" />
        </property>
        <property name="vehicleid" type="java.lang.String">
            <column name="VEHICLEID" />
        </property>
        <property name="distancerealtime" type="java.lang.Double">
            <column name="DISTANCEREALTIME" />
        </property>
        <property name="maximumspeedrealtime" type="int">
            <column name="MAXIMUMSPEEDREALTIME" />
        </property>
        <property name="calledatallstops" type="java.lang.Boolean">
            <column name="CALLEDATALLSTOPS" />
        </property>
        <property name="departuredelay" type="int">
            <column name="DEPARTUREDELAY" />
        </property>
        <property name="maximumdelay" type="int">
            <column name="MAXIMUMDELAY" />
        </property>
        <property name="minimumdelay" type="int">
            <column name="MINIMUMDELAY" />
        </property>
        <property name="phonenumber" type="java.lang.String">
            <column name="PHONENUMBER" />
        </property>
        <property name="comment_id" type="int">
            <column name="COMMENT_ID" />
        </property>
        <property name="arrivaldelayprojection" type="java.lang.Boolean">
            <column name="ARRIVALDELAYPROJECTION" />
        </property>
        <property name="departuredelayprojection" type="java.lang.Boolean">
            <column name="DEPARTUREDELAYPROJECTION" />
        </property>
        <property name="maximumdelayprojection" type="java.lang.Boolean">
            <column name="MAXIMUMDELAYPROJECTION" />
        </property>
        <property name="maximumspeedrealtimedataincomplete" type="java.lang.Boolean">
            <column name="MAXIMUMSPEEDREALTIMEDATAINCOMPLETE" />
          </property>
          <property name="minmaxdelaydataincomplete" type="java.lang.Boolean">
              <column name="MINMAXDELAYDATAINCOMPLETE" />
          </property>
          <property name="minimumdelayprojection" type="java.lang.Boolean">
              <column name="MINIMUMDELAYPROJECTION" />
          </property>
          <property name="realtimearrivalprojection" type="java.lang.Boolean">
              <column name="REALTIMEARRIVALPROJECTION" />
          </property>
          <property name="realtimedepartureprojection" type="java.lang.Boolean">
              <column name="REALTIMEDEPARTUREPROJECTION" />
            </property>
         </class>
    </hibernate-mapping>

and following is the main hibernate.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
                                         "http://hibernate.sourceforge.net/hibernate-
configuration-3.0.dtd">
<hibernate-configuration>
 <session-factory >
  <!-- Database connection settings -->
  <property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/newTestDB</property>
  <property name="connection.driver_class">org.postgresql.Driver</property>
  <property name="connection.username">postgres</property>
  <property name="connection.password">usman123</property>
  <property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
  <!-- SQL dialect - generate SQL for a particular database -->
  <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
  <!-- Echo all executed SQL statements -->
  <property name="show_sql">false</property>
  <!-- Automatic schema creation (begin) === 
<property name="hibernate.hbm2ddl.auto">create</property>  
 Enable Hibernate's automatic session context management -->
  <property name="current_session_context_class">thread</property>
  <!-- Mapping resource configuration files -->
  <mapping resource="de/db/journeyTracker/model/TestTable.hbm.xml"/>
  <mapping resource="de/db/journeyTracker/model/gpspos.hbm.xml"/>
  <mapping resource="de/db/journeyTracker/model/journey.hbm.xml"/>
  <mapping resource="de/db/journeyTracker/model/trip.hbm.xml"/>


    </session-factory> </hibernate-configuration>

Edit:

Exception in thread "main" java.lang.ClassCastException: java.lang.Integer cannot be cast to de.db.journeyTracker.model.journey
    at de.db.journeyTracker.model.journey.findalljourney(journey.java:323)

I tried the following code.. AS you suggested .. But Still it is giving the exception

           List<Object[]> allJourney;
        allJourney = query.list();
        int Count = 0;
        for (Object[] Journey : allJourney)                 
        {                           

           String strJourneyId =  ((journey) Journey[0]).getJourneyid().toString();
           String strOperatingDay = ((journey) Journey[0]).getOperatingday().toString();
           String strLineName = ((journey) Journey[0]).getLinename();
           String strSchedualeDeparture = ((journey) Journey[0]).getScheduledeparture().toString();
           String strSchedualeDepartureStopName = ((journey) Journey[0]).getScheduledeparturestopname();


          System.out.println(strJourneyId + " " + strOperatingDay + " " + strLineName + " " + strSchedualeDeparture + " " + strSchedualeDepartureStopName);
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T19:22:20+00:00Added an answer on June 7, 2026 at 7:22 pm

    This query:

    SELECT j.id , j.operatingday, j.linename,  
           j.scheduledeparture, j.scheduledeparturestopname 
    FROM journey j
    

    does not select List of Journey instances. Instead it selects List of Object arrays. Elements of array match to values in select list:

       [0] = j.id
       [1] = j.operatingday
       ...
    

    Use following instead:

       SELECT j FROM journey j
    

    But if you want to stick with returned array, go for:

      List<Object[]>  allJourney = query.list(); 
      //do what ever you need to do with result:
      for (Object[] row: allJourney) {
          Integer id = (Integer) row[0];
          Date operatingday = (Date) row[1];
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm facing a rather strange Issue when trying to load data from an XML-Webservice.
I'm facing strange error. I use Glassfish 3.1.1 withn jdk7 and since some time
I am facing strange issue. I have wep-part that reads data from user's profile.
I am facing very strange problem. After debugging from my side, I thought to
I am facing a strange error in cakephp2.0. I have created two layouts -
I am facing strange issue i am getting string from database and comparing with
Im facing a strange issue trying to move from sql server to oracle. in
I am facing a strange behavior by CakePHP 2.1: I have a method, $this->Time->getTime();
i am able to parse the XML file. but i am facing strange error.
I'm facing a (strange) problem: I'd like to retrieve the number of phone's numbers

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.