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 500705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:06:53+00:00 2026-05-13T06:06:53+00:00

I am not certain what I am doing wrong, but I have a class

  • 0

I am not certain what I am doing wrong, but I have a class that has a class within it, so when I save the Skill class the user class also gets created, so when I do the join and I want to pull everything in at one time, I get a classcastexception.

This is how I am calling my query.

val retrieved_obj = em.createNamedQuery("findAllSkillsByUser").setParameter("username", user.username ).getResultList().asInstanceOf[java.util.List[Skill]]
assertEquals(1, retrieved_obj.size())
val retrieved = retrieved_obj.get(0).asInstanceOf[Skill]

This is my query:
<query><![CDATA[from Skill a JOIN a.user u WHERE u.username=:username]]></query>

This is what hibernate is actually doing in my test:

Hibernate: insert into users (firstName, lastName, username, id) values (?, ?, ?, ?)
Hibernate: insert into skills (datestarted, name, position, rating, skill_user_fk, id) values (?, ?, ?, ?, ?, ?)
Hibernate: select skill0_.id as id64_0_, user1_.id as id63_1_, skill0_.datestarted as datestar2_64_0_, skill0_.name as name64_0_, skill0_.position as position64_0_, skill0_.rating as rating64_0_, skill0_.skill_user_fk as skill6_64_0_, user1_.firstName as firstName63_1_, user1_.lastName as lastName63_1_, user1_.username as username63_1_ from skills skill0_ inner join users user1_ on skill0_.skill_user_fk=user1_.id where user1_.username=?

I expect the problem is all the user1 parts in the select.

The Skill class just has some setters/getters, basically, so I removed most of the annotations but the foreign key one:

  var id : Int = _
  var name : String = ""
  var position : Int = _
  var dateStarted : Date = new Date()
  var rating : SkillRating.Value = SkillRating.unknown

  @OneToOne{val fetch = FetchType.EAGER, val cascade=Array(CascadeType.PERSIST, CascadeType.REMOVE)}
  @JoinColumn{val name = "skill_user_fk", val nullable = false}
  var user : User = _

This is the User class:

  var id : Int = _
  var firstName : String = ""
  var lastName : String = ""
  var username : String = ""

This is my error:

java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to jblack.resumeapp.lift.model.Skill

I would rather no just select the Skill attributes and then have to do another query for the user, as that will be less efficient as my classes get more complicated.

  • 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-05-13T06:06:54+00:00Added an answer on May 13, 2026 at 6:06 am

    You’re selecting both Skill and User and getting back an object array containing both as elements.

    You can either treat it as such or rewrite your query a bit:

    select a from Skill a JOIN FETCH a.user u WHERE u.username=:username
    

    to select only Skill but fetch and populate its User association.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 297k
  • Answers 297k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer One time saver you could employ is using public delegate… May 13, 2026 at 7:18 pm
  • Editorial Team
    Editorial Team added an answer // now what? is strncpy(): hostname = malloc(hostnameLength + 1);… May 13, 2026 at 7:18 pm
  • Editorial Team
    Editorial Team added an answer The "common Delphi paradigm" is event (event handler). Eg, you… May 13, 2026 at 7:18 pm

Related Questions

I am using JDK 1.6.0_16, and Scala 2.7.7, compiling with maven. I do mvn
I have not done much database programming at all. I am working from some
I am a solo dev building a WinForm App, C# & .Net 3.5, in
I have an order header table called OrderH. In this table there is a
I am trying to select certain fields from my entity to be used as

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.