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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:33:01+00:00 2026-05-17T15:33:01+00:00

I have a table CompanyList in my Oracle database : CMP_ID INTEGER — ID

  • 0

I have a table CompanyList in my Oracle database :

CMP_ID INTEGER -- ID of company
CMP_NAME VARCHAR2 -- name of company
USR_ID INTEGER -- Foreign key to the USERS table

i have my Spring 3 MVC app all configured using annotations, my POJOs as well , my DAO objects (CompanyDao) using hibernate to retrieve for exemple a list of companies.

CompanyDao :

@Transactional
    public Set<Company> findAllCompanys() throws DataAccessException {

        return findAllCompanies(-1, -1);
    }

    @SuppressWarnings("unchecked")
    @Transactional
    public Set<Company> findAllCompanies(int startResult, int maxRows) throws DataAccessException {
        Query query = createNamedQuery("findAllCompanies", startResult, maxRows);
        return new LinkedHashSet<Company>(query.getResultList());
    }

And my company domain :

@Entity
@NamedQueries( {
        @NamedQuery(name = "findAllCompanies", query = "select myCompany from Company myCompany")})
...
public class Company implements Serializable {
...

Then I setup spring security, so all my pages require identification.

What is the best way to filter the rows returned by CompanyDao, using the USER ID of the current logged in user session ?

  • 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-17T15:33:02+00:00Added an answer on May 17, 2026 at 3:33 pm

    Short answer: SecurityContextHolder.

    Slightly longer answer:
    If the User entity that is the parent side of the user_id foreign key relationship also implements the UserDetails interface, then the User entity can be used directly in Spring’s security context.

    You can call the SecurityContextHolder.getContext() method from either your DAO layer or a layer above it…doesn’t really matter because the instance returned will be scoped to the thread local of the request.

    You can then get the UserDetails from the context instance, cast it to your User entity and pass it as a named parameter to a DAO call.

    As a quick followup, I realize that your original question implied that you’d run the named query as it currently exists and then filter out the non-matching companies. You can still use that approach by comparing the users associated with your company with the user from the security context, but in general I wouldn’t recommend that approach; ask the database for exactly what you need.

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

Sidebar

Related Questions

Technology: Hibernate 3.0 Suppose i have Entity class Company @Entity @Table(name=tbl_companies) public class Company
i have table consist of columns : id,name,job and i have row stored with
I have table sort of like Name |DateOfEvent|EventType ---------------------------------- Smith |10/1/2005 |New Thomas |1/1/2002
I have table with ID who is PK and I have in same table
I have table dates as following dates one two three four date1 id1 id2
i have table , contain firstname and lastname , i used in my query
I have table columns with values in them and when you click the edit
I have table with 2 columns .... id id2 1 1 1 2 1
I have table Event and table Sessions and each event has a set of

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.