Results 1 to 2 of 2

Thread: problems loading aop-proxied bean with hibernate

  1. #1
    Join Date
    May 2011
    Posts
    1

    Default problems loading aop-proxied bean with hibernate

    i'am trying to load a user bean from db via hibernate. the user bean is a session-scoped bean (aop-proxy). i've added the ScopedBeanInterceptor, so now i don't get an unknown enitity exception anymore.

    but when i'm trying to load it with session.load() the bean afterwards hasn't changed.
    spring-config:
    Code:
    <bean id="user" class="testapp.models.User" scope="session">
    		<aop:scoped-proxy/>
    	</bean>
    java-dao-code:
    Code:
    public void findById(User user, Long id) {
    		if (user == null)
    			throw new IllegalArgumentException("user is NULL");
    		if (id == null)
    			throw new IllegalArgumentException("id is NULL");
    
    		Session session = sessionFactory.openSession();
    
    		user.setName("unset");
    		session.load(user, u.getId());
    		LOG.debug("user '" + user.getName() + "' found!"); // user 'unset' found!
    		
    		session.close();
    	}
    when i call the dao-function with a new instance of User and id 1 it works (log-message is user 'Administrator' found!), but when i call it with an aop-proxied User and id 1 i get the log-message user 'unset' found!

    can you help me?
    Last edited by giga; May 28th, 2011 at 12:32 PM.

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    That simply is never going to work... You would need to copy the properties of the hibernate loaded entity to the session scoped bean. A session scoped bean is something else as a hibernate entity.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •