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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:17:53+00:00 2026-06-02T03:17:53+00:00

I have a User class marked as entity which also implements UserDetails. I want

  • 0

I have a User class marked as entity which also implements UserDetails. I want to be able to grab some properties of a certain user, and based on their values, to return specific roles in the getAuthorities method. Many of those properties are however lazy-loaded and require a Hibernate transaction.

I tried anything from making the user class @Transactional to making the UserDetailsService and RememberMeService which I use @Transactional. None of those works!

All of my other DAO and Service classes mapped as transactional work (and they are just simple classes – no other annotations besides a @Transactional on top)

UPDATE: This is the overriden getUserDetails in class User

@Override
    public Collection<? extends GrantedAuthority> getAuthorities() {

        GrantedAuthority auth = new GrantedAuthority() {

            @Override
            public String getAuthority() {
                // TODO Auto-generated method stub
                return "ROLE_USER";
            }
        };

        ArrayList<GrantedAuthority> result = new ArrayList<GrantedAuthority>();

        if (options.size() > 0) {
            for (Option o : options) {
                result.add(createAuthority(Option.getStringType(o.type)));
            }
        }

        result.add(auth);

        return result;

    }
  • 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-02T03:17:54+00:00Added an answer on June 2, 2026 at 3:17 am

    The UserDetails is not a Spring bean and thus is Spring is not going to look for @Transactional on it.

    I would need to see a stack trace but what I’m assuming is that getAuthorities() is being called by another UserDetailsService method directly, i.e., not going through the transactional proxy.

    Inject the PlatformTransactionManager into your UserDetailsService and use a TransactionTemplate in getAuthorities() to wrap your DB accessing code in a transaction.

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

Sidebar

Related Questions

We have an JPA @Entity class (say User) which has a @ManyToOne reference (say
Alright so here is the question. I have a user class which contains a
I have a class User with one field called birthDate which is a java.sql.Date
I have a User, some of which are an employee. This is a one-to-one
Suppose I have a class User with many Customers (marked with hasMany property). In
I have an MVC3 project using the Entity Framework model in which I've marked
i have a User class with a field for the e-mail-address and a password.
I have a user and nested profile class as follows: class User < ActiveRecord::Base
I have a class User that looks like this: class User { private: char*
I have a class User in Rails using Mongoid and Devise. I can't seem

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.