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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:42:33+00:00 2026-06-11T10:42:33+00:00

So I have such classes BaseDao public interface BaseDao<T> { T save(T entity); }

  • 0

So I have such classes

BaseDao

public interface BaseDao<T> {

    T save(T entity);  
}

UserDao

public interface UserDao extends BaseDao<User> {

    User getUserByUserName(String name);

}

GenericDao
public abstract class GenericDao implements BaseDao {

@Autowired
protected SessionFactory sessionFactory;

private Class<?> getEntityClass() {
    return ((Class) ((ParameterizedType) getClass().getGenericSuperclass())
            .getActualTypeArguments()[0]);
}

public T save(T entity) {
    Integer id = (Integer) sessionFactory.getCurrentSession().save(entity);
    return (T) sessionFactory.getCurrentSession().get(getEntityClass(), id);
}

}

UserDaoImpl

@Repository
public class PgUserDaoImpl extends GenericDao<User> implements UserDao {

    public User getUserByUserName(String name) {
        Criteria criteria = sessionFactory.getCurrentSession().createCriteria(
                User.class);
        criteria.add(Restrictions.eq("name", name));

        return (User) criteria.uniqueResult();
    }

}

GenericService

public class GenericService<T extends GenericDao<E>, E> {

    protected T dao;

    public GenericService(T dao) {
        setDao(dao);
    }

    @Transactional
    public E save(E entity) {
        return dao.save(entity);
    }
}

UserServiceImpl

@Service("userServiceImpl")
public class UserServiceImpl extends GenericService<PgUserDaoImpl, User>
        implements UserService {

    @Autowired
    public UserServiceImpl(PgUserDaoImpl dao) {
        super(dao);
    }

    @Autowired
    private UserAssebmler assebmler;

    @Transactional
    @Override
    public UserDetails loadUserByUsername(String name)
            throws UsernameNotFoundException {
        .....
    }

}

So I write test contoller to save user, but I always get Exception
org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here

The contoller
@

Controller
@RequestMapping(value = "/test")
public class TestController {

    @Autowired
    private UserServiceImpl userService;

    @RequestMapping(value = "save", method = RequestMethod.GET)
    public String test() {

        User user = new User();

        user.setName("admin");
        user.setPassword("21232f297a57a5a743894a0e4a801fc3");
        user.setRole(UserRole.ADMIN);

        userService.save(user);

        return "home";
    }

}

Anybody know hot to fix that? Thanks 🙂

  • 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-11T10:42:34+00:00Added an answer on June 11, 2026 at 10:42 am

    I’ve solved my question by extending GenericDao class from HibernateDaoSupport class.

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

Sidebar

Related Questions

Say, I have such classes hierarchy: public interface IRepository { } public class SomeSimpleRepository
Lets say we have a program which contains such classes: public interface AbstractItem {
I have a few classes such that: public class XMLStatusMessage extends XMLMessage {} public
Let's we have a lot of such classes(millions) class WordInfo { string Value; string
I have such design: public interface MyInterface { public abstract List<Sth> getSth(); } public
Suppose I have such exceptions hierarchy: public class A extends RuntimeException { ... }
I have several classes such as Order, Customer, etc. These classes serve for holding
I have created two viewController classes such that one is superclass of another.i have
Is it bad policy to have lots of work classes(such as Strategy classes), that
I have two classes - MyBaseClass and BaseClassContainer - that are declared like such:

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.