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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:48:35+00:00 2026-06-15T18:48:35+00:00

This is a related question to another question: Hibernate exception PropertyNotFoundException when using Transformer

  • 0

This is a related question to another question:

Hibernate exception PropertyNotFoundException when using Transformer

I have several tables joining hql. The tables are like this:

A
- A_ID
- NAME

B
- B_ID
- A_ID

C
- C_ID
- B_ID
- LENGTH
- UNIT

Classes:

@Entity
@Table(name="A")
class A
{
    @Id
    @Column(name="A_ID", updatable=false)
    private Long id;

    @Column(name="NAME", nullable=false, length=10, updatable=false)
    private String name;

    @OneToMany(mappedBy="a", fetch=FetchType.LAZY, cascade={CascadeType.ALL})
    @JoinColumn(name="A_ID", nullable=false)
    private Set<B> bs;

    // Setters and getters
    ...
}

@Entity
@Table(name="B")
class B
{
    @Id
    @Column(name="B_ID", updatable=false)
    private Long id;

    @ManyToOne
    @JoinColumn(name="A_ID", nullable=false, insertable=true, updatable=false)
    private A a;

    @OneToMany(mappedBy="b", fetch=FetchType.LAZY, cascade={CascadeType.ALL})
    @JoinColumn(name="B_ID", nullable=false)
    private Set<C> cs;

    @Transient
    private Double length;

    @Transient
    private String unit;

    // Setters and getters
    ...
}

@Entity
@Table(name="C")
class C
{
    @Id
    @Column(name="C_ID", updatable=false)
    private Long id;

    @ManyToOne
    @JoinColumn(name="B_ID", nullable=false, insertable=true, updatable=false)
    private B b;

    @Column(name="LENGTH", nullable=false, updatable=false)
    private Double length;

    @Column(name="UNIT", nullable=false, length=10, updatable=false)
    private String unit;

    // Setters and getters
    ...
}

After solving that issue, it is like this now:

select b.id as id, sum(c.length) as length, min(c.unit) as unit
from B b
left outer join b.c as c
group by b.id

Now the problem is:

I don’t know how to set the alias of A in the returned B object in the HQL. This is causing a NPE when I’m doing this:

b.getA().getName();

Because I don’t know how to set the related object “A” with “B” since there is only an ID in the B table.

Please help. Thank you very much.

  • 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-15T18:48:36+00:00Added an answer on June 15, 2026 at 6:48 pm

    b.getA().getName(); This will throw a NPE because select b.id as id, sum(c.length) as length, min(c.unit) as unit from B b does not include A. When you use the select clause in a HQL query it will only return the fields mentioned.

    Please refer to http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/queryhql.html for more information.

    EDIT:

    If you read through the documentation provided you would have see select cat.mate from Cat cat. This can be incorporated to your query. Add b.A in your select clause and it should work.

    EDIT:

    If select b.id as id, sum(c.length) as length, min(c.unit) as unit
    from B b
    left outer join b.c as c
    group by b.id

    work then
    select b.id as id, sum(c.length) as length, min(c.unit) as unit, b.A
    from B b
    left outer join b.c as c
    group by b.id, b.A

    should as well.

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

Sidebar

Related Questions

Another question related to this one . I have a List<SortableObjects> that is the
This question is related to another question I wrote: Trouble using DOTNET from PHP.
This question is related to another question I asked Basically, I have 2 horizontally
This question is kind of related to another question but I have a specific
There is another possibly related question on this but it didn't have answers and
(this is related to another question about implementation on iPhone) I have a large
I have asked another question related to this in this thread Where to put
This question is related to another question, where I wanted to define a custom
This question is related to another question of mine. Thanks to some help I
This question is related to another question I just posted . I'm prepping for

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.