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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:28:26+00:00 2026-06-06T03:28:26+00:00

Here is my question – There are two classes Order and PaymentType . An

  • 0

Here is my question –

There are two classes Order and PaymentType. An order will have one PaymentType. Now PaymentType is an abstract class and there are other two classes called CreditCardPaymentType and PaypalPaymentType which extends PaymentType class. In hibernate they are modeled as Single_Table strategy. CreditCardPaymentType contains a field called CreditCardNumber. I am writing following HQL and my intention is to eagerly load the CreditCardNumber entity.

session.createQuery("select order from Order as order " +
                "inner join fetch order.paymentType.Unknown");

What should come in place of “Unknown”? Since PaymentType class doesn’t know anything about CrediCardNumber class, what can I put in the above query to eagerly load CreditCardNumber.

Thanks in advance.

  • 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-06T03:28:29+00:00Added an answer on June 6, 2026 at 3:28 am

    What you want to do doesn’t work anyway.

    In Order you can’t make an entity of type PaymentType and load it with hibernate. PaymentType is abstract and as consequence it can’t be instanciated. Hibernate needs a constructor when loading the entity from so database. So you can’t map abstract classes, you only can map implementing classes which have at least a parameterless constructor.

    => In the mapping of Order you have to specify if order.paymentType is CreditCardPaymentType or PaypalPaymentType. And that solves your problem, because then you know what unknown really is.

    To solve your task: At database side you can continue with all payment types in one table. At Java side you have two possibilities (both meant as an idea):

    1. You make PaymentType not abstract, with two methods boolean isCreditCardPayment() and boolean isPaypalCardPayment(), and PaymentType contains all columns of the database table. You only use this class and you forget the classes PaypalPaymentType and CreditCardPaymentType.

    or

    1. In the mapping of both PaypalPaymentType and CreditCardPaymentType you put a where condition ensuring only the rows for the correct payment type are loaded. In Order you drop the property paymentType and as a replacement you add two properties paypalPaymentType and creditcardPaymentType, which are referencing to the two Java classes. When loading the Order, one of the two properties will be null. For convenience you can make a method PaymentType getPaymentType(), which returns the not null payment type, but this convenience method you can’t use in HQL queries.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

here is question: i have 2 threads: the main one and the other. on
Similar question here but this is slightly different... I have two tables that I
Jquery question here. I would like to get the CLASS tag of the only
Newbie question here but for some reason I cant figure this out. I have
Simple question here: is there any way to convert from a jagged array to
C# question here.. I have a UTF-8 string that is being interpreted by a
quick question here. Is there any Wordpress 3.0 documentation available? Some kind of list
Here is question for all those who have delivered WCF solutions to their clients/customers
First question here. I am trying to instantiate a generic class using the type
First question here! I'm trying to create a mail system and now working on

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.