Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
    Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to com.dao.entity.Login

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hi,
Please helm me to handle this exception




log4j:WARN Please initialize the log4j system properly.
[TestNG] Running:
C:\User\AppData\Local\Temp\testng-eclipse--1736054659\testng-customsuite.xml

Hibernate: select login0_.LOGIN_ID as LOGIN1_23_0_, role1_.ROLE_ID as ROLE1_28_1_, login0_.AUDIT_CREATED_DT as AUDIT2_23_0_, login0_.AUDIT_MODIFIED_DT as AUDIT3_23_0_, login0_.EMPLOYEE_ID as EMPLOYEE12_23_0_, login0_.AUDIT_USER as AUDIT13_23_0_, login0_.IP_ADDRESS as IP4_23_0_, login0_.LAST_LOGIN_ATTEMPT as LAST5_23_0_, login0_.LAST_SUCCESSFUL_LOGIN as LAST6_23_0_, login0_.NO_OF_ATTEMPTS as NO7_23_0_, login0_.password as password23_0_, login0_.PASSWORD_EXP_DT as PASSWORD9_23_0_, login0_.AUDIT_ROLE as AUDIT14_23_0_, login0_.SECURITY_ANSWER as SECURITY10_23_0_, login0_.SECURITY_QUESTION_ID as SECURITY15_23_0_, login0_.username as username23_0_, role1_."ROLE" as ROLE2_28_1_, role1_.ROLE_STATUS_ID as ROLE3_28_1_ from Login login0_ inner join "ROLE" role1_ on login0_.AUDIT_ROLE=role1_.ROLE_ID
Hibernate: select employee0_.EMPLOYEE_ID as EMPLOYEE1_8_5_, employee0_.AUDIT_CREATED_DT as AUDIT2_8_5_, employee0_.AUDIT_MODIFIED_DT as AUDIT3_8_5_, employee0_.DESIGNATION_ID as DESIGNA11_8_5_, employee0_.dob as dob8_5_, employee0_.doj as doj8_5_, employee0_.AUDIT_USER as AUDIT12_8_5_, employee0_.EMPLOYEE_STATUS_ID as EMPLOYEE13_8_5_, employee0_.FIRST_NAME as FIRST6_8_5_, employee0_.gender as gender8_5_, employee0_.IP_ADDRESS as IP8_8_5_, employee0_.LAST_NAME as LAST9_8_5_, employee0_.MIDDLE_NAME as MIDDLE10_8_5_, employee0_.AUDIT_ROLE as AUDIT14_8_5_, designatio1_.DESIGNATION_ID as DESIGNAT1_6_0_, designatio1_.designation as designat2_6_0_, employee2_.EMPLOYEE_ID as EMPLOYEE1_8_1_, employee2_.AUDIT_CREATED_DT as AUDIT2_8_1_, employee2_.AUDIT_MODIFIED_DT as AUDIT3_8_1_, employee2_.DESIGNATION_ID as DESIGNA11_8_1_, employee2_.dob as dob8_1_, employee2_.doj as doj8_1_, employee2_.AUDIT_USER as AUDIT12_8_1_, employee2_.EMPLOYEE_STATUS_ID as EMPLOYEE13_8_1_, employee2_.FIRST_NAME as FIRST6_8_1_, employee2_.gender as gender8_1_, employee2_.IP_ADDRESS as IP8_8_1_, employee2_.LAST_NAME as LAST9_8_1_, employee2_.MIDDLE_NAME as MIDDLE10_8_1_, employee2_.AUDIT_ROLE as AUDIT14_8_1_, employeest3_.EMPLOYEE_STATUS_ID as EMPLOYEE1_16_2_, employeest3_.status as status16_2_, role4_.ROLE_ID as ROLE1_28_3_, role4_."ROLE" as ROLE2_28_3_, role4_.ROLE_STATUS_ID as ROLE3_28_3_, status5_.STATUS_ID as STATUS1_33_4_, status5_.status as status33_4_ from Employee employee0_ left outer join Designation designatio1_ on employee0_.DESIGNATION_ID=designatio1_.DESIGNATION_ID left outer join Employee employee2_ on employee0_.AUDIT_USER=employee2_.EMPLOYEE_ID left outer join EMPLOYEE_STATUS employeest3_ on employee2_.EMPLOYEE_STATUS_ID=employeest3_.EMPLOYEE_STATUS_ID left outer join "ROLE" role4_ on employee2_.AUDIT_ROLE=role4_.ROLE_ID left outer join Status status5_ on role4_.ROLE_STATUS_ID=status5_.STATUS_ID where employee0_.EMPLOYEE_ID=?
Hibernate: select designatio0_.DESIGNATION_ID as DESIGNAT1_6_0_, designatio0_.designation as designat2_6_0_ from Designation designatio0_ where designatio0_.DESIGNATION_ID=?
Hibernate: select securityqu0_.SECURITY_QUESTION_ID as SECURITY1_30_0_, securityqu0_.question as question30_0_ from SECURITY_QUESTION securityqu0_ where securityqu0_.SECURITY_QUESTION_ID=?
Hibernate: select employee0_.EMPLOYEE_ID as EMPLOYEE1_8_5_, employee0_.AUDIT_CREATED_DT as AUDIT2_8_5_, employee0_.AUDIT_MODIFIED_DT as AUDIT3_8_5_, employee0_.DESIGNATION_ID as DESIGNA11_8_5_, employee0_.dob as dob8_5_, employee0_.doj as doj8_5_, employee0_.AUDIT_USER as AUDIT12_8_5_, employee0_.EMPLOYEE_STATUS_ID as EMPLOYEE13_8_5_, employee0_.FIRST_NAME as FIRST6_8_5_, employee0_.gender as gender8_5_, employee0_.IP_ADDRESS as IP8_8_5_, employee0_.LAST_NAME as LAST9_8_5_, employee0_.MIDDLE_NAME as MIDDLE10_8_5_, employee0_.AUDIT_ROLE as AUDIT14_8_5_, designatio1_.DESIGNATION_ID as DESIGNAT1_6_0_, designatio1_.designation as designat2_6_0_, employee2_.EMPLOYEE_ID as EMPLOYEE1_8_1_, employee2_.AUDIT_CREATED_DT as AUDIT2_8_1_, employee2_.AUDIT_MODIFIED_DT as AUDIT3_8_1_, employee2_.DESIGNATION_ID as DESIGNA11_8_1_, employee2_.dob as dob8_1_, employee2_.doj as doj8_1_, employee2_.AUDIT_USER as AUDIT12_8_1_, employee2_.EMPLOYEE_STATUS_ID as EMPLOYEE13_8_1_, employee2_.FIRST_NAME as FIRST6_8_1_, employee2_.gender as gender8_1_, employee2_.IP_ADDRESS as IP8_8_1_, employee2_.LAST_NAME as LAST9_8_1_, employee2_.MIDDLE_NAME as MIDDLE10_8_1_, employee2_.AUDIT_ROLE as AUDIT14_8_1_, employeest3_.EMPLOYEE_STATUS_ID as EMPLOYEE1_16_2_, employeest3_.status as status16_2_, role4_.ROLE_ID as ROLE1_28_3_, role4_."ROLE" as ROLE2_28_3_, role4_.ROLE_STATUS_ID as ROLE3_28_3_, status5_.STATUS_ID as STATUS1_33_4_, status5_.status as status33_4_ from Employee employee0_ left outer join Designation designatio1_ on employee0_.DESIGNATION_ID=designatio1_.DESIGNATION_ID left outer join Employee employee2_ on employee0_.AUDIT_USER=employee2_.EMPLOYEE_ID left outer join EMPLOYEE_STATUS employeest3_ on employee2_.EMPLOYEE_STATUS_ID=employeest3_.EMPLOYEE_STATUS_ID left outer join "ROLE" role4_ on employee2_.AUDIT_ROLE=role4_.ROLE_ID left outer join Status status5_ on role4_.ROLE_STATUS_ID=status5_.STATUS_ID where employee0_.EMPLOYEE_ID=?
Hibernate: select employeest0_.EMPLOYEE_STATUS_ID as EMPLOYEE1_16_0_, employeest0_.status as status16_0_ from EMPLOYEE_STATUS employeest0_ where employeest0_.EMPLOYEE_STATUS_ID=?
FAILED: hqlTest
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to .dao.entity.Login
at com.cinemasurvey.test.login.LoginDAOTest.hqlTest(LoginDAOTest.java:147)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.MethodInvocationHelper$1.runTestMethod(MethodInvocationHelper.java:200)
at org.springframework.test.context.testng.AbstractTestNGSpringContextTests.run(AbstractTestNGSpringContextTests.java:158)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeHookable(MethodInvocationHelper.java:212)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:707)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:335)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:330)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)




@Transactional
@ContextConfiguration(locations = "classpath:daoContexttest.xml")
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = false)
public class LoginDAOTest extends AbstractTestNGSpringContextTests {

@Autowired
LoginDAO loginDAO;

EntityManager entityManager;

public LoginDAO getLoginDAO() {
return loginDAO;
}

public void setLoginDAO(LoginDAO loginDAO) {
this.loginDAO = loginDAO;
}

public EntityManager getEntityManager() {
return entityManager;
}

@PersistenceContext
public void setEntityManager(EntityManager entityManager) {
this.entityManager = entityManager;
}

@Test
public void hqlTest() {
Login login;



String hqlQuery = "FROM Login login inner join login.role role";

login= (Login) entityManager.createQuery(hqlQuery).getResultList().get(0);
System.out.println(login.getUsername());



}

}
 
Marshal
Posts: 74746
336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
I am closing this discussion because it appears to be the same question you asked elsewhere.
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic