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();
}
You could use the METHOD scope:
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.