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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:06:55+00:00 2026-05-30T09:06:55+00:00

in my Bean I have the following code shown below. What I want: I’d

  • 0

in my Bean I have the following code shown below.

What I want: I’d like to get every time, when I call the factory a new random person-List.

What I get: I do get every time the same person-list. The obviously reason is, that the factory method only creates a new object, if the current object is null i.e. only at the first factory call.

How do I have to change the code, that I get a new object every time?

Thank you!

@Logger                  private Log log;
@In                      private EntityManager entityManager;
@In                      private LocaleSelector localeSelector;

@Factory("personList")
public List<Person> createPersonList() {
    log.info("Creating Person List.");

    return entityManager.createQuery(
    "SELECT p FROM Person p ORDER by random()")
    .setMaxResults(3)
    .getResultList();
}
  • 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-30T09:06:57+00:00Added an answer on May 30, 2026 at 9:06 am

    You could use the METHOD scope:

    @Factory(value="personList", scope=ScopeType.METHOD)
    public List<Person> createPersonList() {
    

    Technically, the METHOD scope is meant for internal use, though, so if a new list for each HTTP request is acceptable, I’d use ScopeType.EVENT.

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

Sidebar

Related Questions

As mentioned below I have made changes to the code which looks like following
Imagine that i have the following code: <a:repeat value=#{bean.getList()} var=x > <li class=la> <span>
I have the following code: public interface IMyInterface { DataGrid ItemsInGrid { get; set;
I have the following code on my web-page. It iterates a list, creates new
I have the following bean defined: <sec:authentication-manager alias=authenticationManager> <sec:authentication-provider user-service-ref=userDetailsService /> </sec:authentication-manager> I guess
Say I have the following simple java bean: class MyBean { private Date startDate;
Please consider the following: we have a Spring bean B which is advised with
I have bean like: <bean id=test> ........... <property name=myQuery value=select a,b,c from table1 where
I have following code and now I have type, but I need to have
Hi i have a following question. According to spring docs tx:annotation-driven only respects bean

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.