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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:36:21+00:00 2026-06-13T16:36:21+00:00

I need to build a Vehicle domain object. All Vehicle objects will have about

  • 0

I need to build a Vehicle domain object. All Vehicle objects will have about 5 properties… no big deal. I annotate the class with @Entity, slap in an id annotated with @Id. My problem is, there are two other types of specialty vehicles I need to account for. One needs to hold 2 additional string values, and the other needs to hold a list of strings.

I would like to be able to do a findAll() and get all of the vehicles, so I’m not really sold on creating completely separate domain objects for the other two types of vehicles and having completely separate tables for them. I toyed around with an idea to create an “AdditionalProperties” abstract class, make it a member of Vehicle, then extend it for my two specialty vehicles, but I quickly got lost in the proper way to annotate it and map it to the database. But even then I’d be stuck with writing lots of monolithic if statements to check vechicle type and cast that class etc etc

My other thought was just to include the extra fields in the single Vehicle domain object I have now (even though they don’t make any sense for all the other types of vehicles) and leave the values null except for when it is one of the specialty vehicles.

Does anybody have any ideas on how I should approach this with possibly some examples of how the classes should be annotated?

  • 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-13T16:36:22+00:00Added an answer on June 13, 2026 at 4:36 pm

    Why don’t you simply create two subclasses of Vehicle, and containing the additional properties? Hibernate supports inheritance just fine. You’ll have three options to persist the entity inheritance tree:

    • everything in a single table (often the fastest and simplest option)
    • every entity in its own table
    • common properties in a common table, and additional sub-entity properties in their own table.

    Whatever solution you choose, selecting vehicles will select all the kinds of vehicles satisfying the criteria. Hibernate queries are polymorphic.

    Read the documentation.

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

Sidebar

Related Questions

I need to build a keystore with all the needed SSL certificates to make
I need to build a dynamic linq query with or operators. I have seen
I need to build a multi-language site, where the client will add records in
I need build Queue that will stay allways sorted by its keys . the
Hello everyone here... I need to build up a swing application related to vehicle
I need to build up the matrix of matrices. Say, for all $1\leq i,j\leq
I need to build a dynamic form from database. I have following Entity to
This I'm trying for transfer my current Apache/Modperl site to Starman, and need build
I need to build app with user messages (dialogs). I've solved this problem by
I need to build a feature like most of the banks use. Where.. if

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.