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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:48:39+00:00 2026-06-14T19:48:39+00:00

I know that my question very strange and difficult to understand I create some

  • 0

I know that my question very strange and difficult to understand

I create some structure of my project. But every time I faced with different problems as could not initialize proxy - No session again or Not serializable exception

I want to get some advice or help. I try to use annotation transactional and I don’t understand in which case I should use implements Serializable. Of course, I know that if I want to use bean with view scope I should use client saving method and bean should be implenebts seriailzable. If I user other non-primitive fields its also should be serializable. It means that using inmplenets Serializable in both interfaces IDao and ITestSystemService nothing bad.

My generic DAO

public interface IDao<T> extends Serializable{
    List<T> getAll() throws DAOException;
    T get(Long id) throws DAOException;
}

DAO implementation

@Repository("subjectDAO")
@Scope("prototype")
public class SubjectHibernateDAO implements ISubjectDAO{

    private static final long serialVersionUID = 1L;

    private static final Logger logger = Logger.getLogger(SubjectHibernateDAO.class);

    @Autowired
    private SessionFactory hibernateSessionFactory;
    //getter and setter

    @SuppressWarnings("unchecked")
    @Override
    public List<Subject> getAll() throws DAOException {
        Session session = hibernateSessionFactory.getCurrentSession();

        Transaction transaction = null;
        List<Subject> subjectList = null;
        try{
            transaction = session.beginTransaction();
            subjectList = session.getNamedQuery(GET_ALL_SUBJECTS_NAME_QUERY).list();
            transaction.commit();
        }  catch (HibernateException e) {
            if (transaction != null)
                transaction.rollback();
            logger.error(SQL_EXCEPTION_IN_QUERY, e);
            throw new DAOException(SQL_EXCEPTION_IN_QUERY, e);
        }
        return subjectList;
    }

// Generic service interface
public interface ITestSystemService<T> extends Serializable{

    List<T> getAll() throws DAOException;
}

//Service realization
@Service("subjectService")
@SessionScoped
public class SubjectServiceImpl implements ISubjectService{

    private static final long serialVersionUID = 1L;

    @Autowired
    @Qualifier("subjectDAO")
    private IDao<Subject> subjectDAO;

    public void setSubjectDAO(IDao<Subject> subjectDAO) {
        this.subjectDAO = subjectDAO;
    }

    @Override
    public List<Subject> getAll() throws DAOException {
        return subjectDAO.getAll();
    }

}

In my JSF bean contoller with view scope I every time getting problem with this structure.

What I should change in structure of my application?

  • 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-14T19:48:41+00:00Added an answer on June 14, 2026 at 7:48 pm

    I would make the following changes to what you have written:

    SubjectServiceImpl

    • This could be singleton scoped – services don’t have state.
    • You don’t need a setter for subject DAO (I would use constructor injection and make the subjectDAO final.
    • Make the getAll method @Transaction (as you eluded to in your question) – this will ensure that Spring binds a Hibernate session to the thread of execution. This is then available using SessionFactory#getCurrentSession().

    SubjectHibernateDAO

    • Remove code concerned with transactions e.g. transaction = session.beginTransaction(). The provision of a session will be handled by the @Transactional annotation on your service method.
    • Remove all rollback code
    • Make the DAO singleton scoped – again no state. It should depend on a final SessionFactory variable.
    • Inject the SessionFactory via a constructor (field injection is not great).

    Once you’ve done all of the above you might find that your problem goes away (it’s not obvious from your question what the actual problem is). The biggest problem with your code is the manual transaction mixed with the use of SessionFactory#getCurrentSession().

    You haven’t supplied your Spring configuration but to use @Transactional you will need to enable transactional proxying behaviour in spring. You can do this in xml using and with annotations using @EnableTransactionManagement.

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

Sidebar

Related Questions

I know that very similar question was posted some time ago and it was
I know that this question is very similar to the question posted here .
Ok, I know that question is not very informative.. Someome feel free to change
I know that my question will be very similar to other ones already asked
I know that this is a repeated question. I have found very similar questions
I know that similar questions have been asked before, but I am very much
I know that such type of questions exist in SF but they are very
I know that even a question Erlang or Java seems quite strange, because they
I know that the question may seem very easy. I am trying to display
This is going to seem a very strange question but im just playing about

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.