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

  • Home
  • SEARCH
  • 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 599121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:27:48+00:00 2026-05-13T16:27:48+00:00

I have two class definitions in my Spring MVC web application named Class and

  • 0

I have two class definitions in my Spring MVC web application named Class and Object respectively:

public Class {
//instance variables
int classId;
int className;


}


public Object {
    //instance variables
int objectId;
int objectName;


}

I also have a service that that returns a list of Class and Object defined as follows.

package com.service;


import java.util.ArrayList;
import java.util.List;
import java.util.Iterator;
import com.domain.Class;
import com.domain.Object;
import com.service.SearchManager;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;


import java.io.Serializable;

public class SempediaSearchManager implements com.service.SearchManager {

    private SessionFactory sessionFactory;
    private List<Class> classes;
    private List<Object> objects;



     public List<Class> getClassSeedSearch(String classSeed) {
         Configuration configuration = new Configuration().configure();
         sessionFactory = configuration.buildSessionFactory();
         Session session = sessionFactory.openSession();
         try {
         Query query = session.createQuery("from Class c where lower(c.className) like lower('"
                 + classSeed + "%')");
         return query.list();
         } finally {
         session.close();
         }

     }
     public List<Object> getObjectSeedSearch(String objectSeed) {
         Configuration configuration = new Configuration().configure();
         sessionFactory = configuration.buildSessionFactory();
         Session session = sessionFactory.openSession();
         try {
         Query query = session.createQuery("from Object o where lower(o.objectName) like lower('"
                 + objectSeed + "%')");
         return query.list();
         } finally {
         session.close();
         }
     }


     ?????
     skeleton method
     public List<ClassesAndObjects> getObjectorClassSeedSearch(String objectOrClassSeed) {
      ?????
     }

The view I present has a search box that allow a user to search for either classes or objects based on the repsective list returned by the methods getObjectSeedSearch, and getClassSeedSearch – List, List respectively

What I’d like to allow the search text box to simply search for both classes and objects, returning perhaps a merged list – List – if you would that has both classes and Objects by leveraging a method getObjectorClassSeedSearch

What would be the best way forward in implementing this.
I vaguely know I’d want to create a wrapper class that would take both Class and Object and perhaps polymorphically at run time determine what instance and item is when being returned of propped from the list. I guessing I would have a corresponding bean for this in my application. perhaps an exercise with generics.

What would be an efficient way to proceed?

Thanks

  • 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-13T16:27:49+00:00Added an answer on May 13, 2026 at 4:27 pm

    Have a common interface/abstract class for both of them:

    public abstract class Name
    {
        private int id;
        private String name;
        // all attendant ctors and getter/setter stuff here.
    }
    

    You can return one List<Name> as needed that way.

    Good names matter. Overloading “Class” and “Object”, when they’re already part of the java.lang package, will only cause you and future maintainers of your code grief.

    These might be examples, but I see no reason for either of these classes. There’s no abstraction or rich behavior. I’d say this is a design worth rethinking, based on what I see here.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer While it's likely possible to have mouseReleased give the actual… May 14, 2026 at 3:41 am
  • Editorial Team
    Editorial Team added an answer A binary heap is a lot better for what you… May 14, 2026 at 3:41 am
  • Editorial Team
    Editorial Team added an answer you could use Object#inspect: { :id => 5, :foos =>… May 14, 2026 at 3:41 am

Related Questions

I'm building an ASP.Net MVC website. Rather than have everything in one project, I've
How can I implement the so called repository pattern that Rob Conery shows in
I need to make an outer join query that retrieves all of the definitions
I have a class that represents credit card details. To represent valid from and
I have some template code that I would prefer to have stored in a

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.