Announcement Announcement Module
Collapse
No announcement yet.
Transaction with Hibernate : NoSuchMethodError org/hibernate/proxy/LazyInitializer Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Transaction with Hibernate : NoSuchMethodError org/hibernate/proxy/LazyInitializer

    Hi,

    I use this context:

    Code:
    <beans>
    	
    	<!-- PostgreSQL JDBC DataSource configuration -->
    	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    		<property name="driverClassName" value="org.postgresql.Driver"/>
    		<property name="url" value="jdbc:postgresql://m0/manager"/>
    		<property name="username" value="manager"/>
    		<property name="maxActive" value="-1"/>
    	</bean>	
    	
    	<!-- Hibernate configuration -->
    	<bean id="hibernateSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    		<property name="dataSource" ref="dataSource"/>
    		<property name="configLocation" value="classpath:receiver/hibernate.cfg.xml"/>
    	</bean>
    	<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    		<property name="sessionFactory" ref="hibernateSessionFactory"/>
    	</bean>    
    	<bean id="transactionTransactionTemplate" class="org.springframework.transaction.support.TransactionTemplate">
    		<property name="transactionManager" ref="transactionManager"/>
    	</bean>
        
    	<!-- Business logic beans -->
    	<bean id="HTest" class="htest.ReaderInSeparateSessions" init-method="read">
    		<property name="transactionTemplate" ref="transactionTransactionTemplate"/>
    		<property name="hibernateSessionFactory" ref="hibernateSessionFactory"/>
    	</bean>
    	
    </beans>
    ReaderInSeparateSessions.java is:

    Code:
    public class ReaderInSeparateSessions {
    
    	private Log log = LogFactory.getLog(getClass());
    	private int i=0;
    	
    	private TransactionTemplate transactionTemplate;
    	private SessionFactory hibernateSessionFactory;
    	private Session hibernateSession = null;	
    	
    	public void setHibernateSessionFactory(SessionFactory hibernateSessionFactory) {
    		this.hibernateSessionFactory = hibernateSessionFactory;
    	}
    
    	public void setTransactionTemplate(TransactionTemplate transactionTemplate) {
    		this.transactionTemplate = transactionTemplate;
    	}
    
    	public void read() {
    		hibernateSession = hibernateSessionFactory.getCurrentSession();
    		while (true) {
    			transactionTemplate.execute(new TransactionCallbackWithoutResult() {
    			    @SuppressWarnings("unchecked")
    				public void doInTransactionWithoutResult(TransactionStatus status) {
    			    	for (MessageFilter filter : (List<MessageFilter>)hibernateSession.createQuery("from MessageFilter").list()) {
    			    		log.debug("Filter ["+(i++)+"] : ["+filter+"]");
    					}
    			    }
    			});
    		}
    	}
    }
    On running at 1700 iteration I got:

    Code:
    Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'HTest' defined in class path resource [htest/context.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: manager.broker.model.User.getHibernateLazyInitializer()Lorg/hibernate/proxy/LazyInitializer;
    Caused by: java.lang.NoSuchMethodError: manager.broker.model.User.getHibernateLazyInitializer()Lorg/hibernate/proxy/LazyInitializer;
            at manager.broker.model.User$$EnhancerByCGLIB$$1d14b5c9.getHibernateLazyInitializer(<generated>)
            at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:274)
            at org.hibernate.type.EntityType.resolve(EntityType.java:303)
            at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:116)
            at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:842)
            at org.hibernate.loader.Loader.doQuery(Loader.java:717)
            at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
            at org.hibernate.loader.Loader.doList(Loader.java:2145)
            at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
            at org.hibernate.loader.Loader.list(Loader.java:2024)
            at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:375)
            at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:308)
            at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:153)
            at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1106)
            at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
            at htest.ReaderInSeparateSessions$1.doInTransactionWithoutResult(ReaderInSeparateSessions.java:38)
            at org.springframework.transaction.support.TransactionCallbackWithoutResult.doInTransaction(TransactionCallbackWithoutResult.java:33)
            at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:128)
            at htest.ReaderInSeparateSessions.read(ReaderInSeparateSessions.java:34)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:585)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:999)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:961)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:924)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:415)
            at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:245)
            at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:141)
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:242)
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:156)
            at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:304)
            at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:348)
            at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:92)
            at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:77)
            at htest.HTestStartup.main(HTestStartup.java:11)
    Mapping is:

    Code:
    <hibernate-mapping>
        <class name="manager.broker.model.User" table="MANAGER_USERS">
    		<id name="id" type="integer" column="ID">
    			<generator class="native"/>
    		</id>
    		<property name="userName" length="25" column="USER_NAME" unique="true"/>
    	</class>	
    	<class name="manager.broker.model.MessageFilter" table="MANAGER_MESSAGES_FILTERS">
    		<id name="id" type="integer" column="ID">
    			<generator class="native"/>
    		</id>
    		<property name="expression"/>
    		<property name="error" type="text"/>
    		<many-to-one name="user" not-null="true" column="USER_ID" class="manager.broker.model.User"/>
    	</class>
    </hibernate-mapping>
    I got this error only on selecting from MessageFilter, not from User

    I can't use one session for all transactions because I got:

    Code:
    No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
    Any ideas?

  • #2
    Check this out: http://opensource.atlassian.com/proj...rowse/HHH-1293

    Comment

    Working...
    X