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 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

Related Questions

I have two classes: class Object { public: Object(); virtual void update(); virtual void
I have a two classes: public class Question { public IList<Answer> Answers { get;
I have two classes, and want to include a static instance of one class
I have two Spring proxies set up: <bean id=simpleBean class=org.springframework.aop.framework.ProxyFactoryBean> <property name=target> <ref local=simpleBeanTarget/>
I have two classes declared like this: class Object1 { protected ulong guid; protected
I have two Java classes: B, which extends another class A, as follows :
I have two classes: Action and MyAction . The latter is declared as: class
Ok I have two modules, each containing a class, the problem is their classes
I have an abstract base class which acts as an interface. I have two
I have two classes, Foo and Bar, that have constructors like this: class Foo

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.