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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:09:21+00:00 2026-05-20T18:09:21+00:00

I actually saw this question , but couldn’t get much from it, so I’ll

  • 0

I actually saw this question, but couldn’t get much from it, so I’ll try to be more specific with mine.
I have BaseDAO class in my multi-user web-app that looks like this:

public abstract class BaseDAO<GenType>
{
private HibernateOperations hibernateTemplate;

protected BaseDAO() {}
protected HibernateOperations getHibernateTemplate() {
    return hibernateTemplate;
}
public void setHibernateTemplate(HibernateOperations hibernateTemplate) {
    this.hibernateTemplate = hibernateTemplate;
}
protected void initialize(final Object proxy) throws DataAccessException {
    hibernateTemplate.initialize(proxy);
}
public GenType merge(GenType entity) throws DataAccessException {
    return (GenType)hibernateTemplate.merge(entity);
}
protected void persist(GenType entity) throws DataAccessException {
    hibernateTemplate.persist(entity);
}
public void refresh(GenType entity) throws DataAccessException {
    hibernateTemplate.refresh(entity);
}
public void save(GenType entity) throws DataAccessException {
    hibernateTemplate.save(entity);
}
public void saveOrUpdate(GenType entity) throws DataAccessException {
    hibernateTemplate.saveOrUpdate(entity);
}
public void update(GenType entity) throws DataAccessException {
    hibernateTemplate.update(entity);
}
public void delete(GenType entity) throws DataAccessException {
    hibernateTemplate.delete(entity);
}
protected void deleteAll(Collection<GenType> entities) throws DataAccessException {
    hibernateTemplate.deleteAll(entities);
}
protected GenType get(Class<GenType> entityClass, Serializable id) throws DataAccessException {
    return (GenType)hibernateTemplate.get(entityClass, id);
}
}

It’s basically wrapper around HibernateTemplate. All my other DAOs inherit this class and implement appropriate interfaces, which hold some additional methods (like getBySomeAttribute()). So basically these DAOs have only methods. Further more, I have service layer that wraps DAOs. That is, a service class can hold multiple DAOs, and method calls from service layer are intercepted with spring-AOP for auto commit/rollback (transaction demaracation). For example:

public class ModelDAO extends BaseDAO<Model> implements IModelDAO
{
    @Override
    public Model getNew() {
        return new Model();
    }

    @Override
    public List<Model> getBySomeAttr() {
        DetachedCriteria criteria;
        // define some criteria
        return getHibernateTemplate().findByCriteria(criteria);
    }
}

...

public class ModelService
{
    private ModelDAO modelDAO;
    private ElementDAO elementDAO;
    // GET/SET for model and user DAO

    public void doSomethingWithModel() {

        modelDAO.doSomething();
        elementDAO.doSomethingElse();
    }
}

Config is as follows:

<bean id="hibernateTemplate2" class="org.springframework.orm.hibernate3.HibernateTemplate">
    <property name="sessionFactory" ref="sessionFactory2" />
    <property name="maxResults" value="3000" />
</bean>

<!-- DAO -->
<bean id="baseDAO" abstract="true" 
    class="org.irvas.backend.dao_implement.BaseDAO" scope="session">
    <property name="hibernateTemplate" ref="hibernateTemplate2" />
</bean>
<bean id="modelDAO" 
    class="org.irvas.backend.dao_implement.ModelDAOImplement" 
    parent="baseDAO" scope="session">
</bean>
<bean id="elementDAO" 
    class="org.irvas.backend.dao_implement.ElementDAOImplement" 
    parent="baseDAO" scope="session">
</bean>

<!-- Service -->
<bean id="modelService" 
    class="org.irvas.backend.service_implement.ModelServiceImplement" scope="session">
    <property name="modelDAO" ref="modelDAO" />
    <property name="elementDAO" ref="elementDAO" />
</bean>
<bean id="elementService" 
    class="org.irvas.backend.service_implement.ElementServiceImplement" scope="session">
    <property name="elementDAO" ref="elementDAO" />
</bean>

So, I’m wondering how should I scope DAO/Service beans for multi-user purposes? I am injecting service beans into prototype controllesrs for GUI.
When I use this configuration (with scope=”session”), I get error like:

Error creating bean with name ‘modelService’: java.lang.IllegalArgumentException setAttribute: Non-serializable attribute: modelDAO

I’d say that this is thrown from Tomcat’s StandardSession.setAttribute(). From this I could conclude that my DAOs should implement Serializable, and what confuses me even more is that I saw exact same code that works without implementing Serializable…

If someone could enlighten me what is going on here, and how to scope DAOs and Services for this particular case, I’d be very grateful…

  • 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-20T18:09:22+00:00Added an answer on May 20, 2026 at 6:09 pm

    There is no need to make your DAOs session-scoped.

    Though Hibernate session has a state, under properly configured transaction management its state is bound to transactions (i.e. different DAO methods called inside the same transactions share the same session, whereas the same method called from different transactions use different sessions).

    So, your DAOs are effectively stateless, and should be singleton-scoped (i.e. default scope).

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

Sidebar

Related Questions

Actually, this question seems to have two parts: How to implement pattern matching? How
I actually have an answer to my question but it is not parallelized so
Disclaimer: This is not actually a programming question, but I feel the audience on
Actually, I'm using this way. Do you have a better way? private bool AcceptJson(HttpRequest
Actually my question is all in the title. Anyway: I have a class and
I actually have two questions regarding the same problem but I think it is
Actually here is a similar topic with little practical value. As far as I
Actually what i am trying to build is like a kind of firewall. It
Actually I am trying to move some box alternatively with in another box. I
What actually happens to the file system when you do a Subclipse Share Project

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.