Announcement Announcement Module
No announcement yet.
Transaction on autowired instance Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Transaction on autowired instance


    I have an entity, which has entitymanager injected that I autowire like this -

    CorporatePackageBeanResolver.getApplicationContext ().getAutowireCapableBeanFactory().autowireBean(th is);

    On that entity object, I have methods annotated with "@Transactional" for lazy loading. My question is, when those methods are invoke, is spring transaction manager going to manage the transaction, like normal spring bean?

    Here I want to mention that, my entity is not spring managed bean, but its dependency is injected.

    If transaction is not managed, then how can i manage trnasaction there?

    The whole code looks like this ----

    public class CategoryEntity extends ModelEntity implements Category {

    @PersistenceContext(unitName = "system")
    protected transient EntityManager entityManager;

    @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    private List<Application> applications = new ArrayList<Application>();

    public CategoryEntity() {

    public CategoryEntity(String name, List<Application> applications) {
    this.applications = applications == null ? new ArrayList<Application>() : applications;

    public List<Application> getApplications() {
    Query query = entityManager.createNamedQuery("CategoryEntity.get Applications");
    query.setParameter("pk", pk);
    List<Application> resultList = query.getResultList();
    return resultList == null ? new ArrayList<Application>() : applications;

    public void setApplications(List<Application> applications) {
    this.applications = applications;