Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Could not instantiate bean class

  1. #1
    Junior Member
    Join Date
    Aug 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Could not instantiate bean class

    Hi ! I've been trying to use hibernate with spring framework for a week by using hibernate (annotations). I am using hibernate-distribution 3.6.5 final and Spring framework 3.0.5 in the application.

    Error log and code is here :http://www.daniweb.com/software-deve...threads/378043

    I wait for some suggestions. Please hlp !


  2. #2
    Junior Member
    Join Date
    Feb 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Could not instantiate bean class

    Check your Link! It don't work !! :-)

  3. #3
    Junior Member
    Join Date
    Aug 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Lightbulb Re: Could not instantiate bean class

    Hi ! I've been trying to integrate hibernate with spring framework for a week by using hibernate annotations. I am using hibernate-distribution 3.6.5 final and Spring framework 3.0.5 in the application.
    Error log looks like as below which troubles me a lot.

    Any piece of idea will be appreciated, please hlp !


    Yeaa you're right.. Here is the code and error log ready for you.. in here the error log displays much better.

    Here dispatcher-servlet.xml :
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xmlns:p="http://www.springframework.org/schema/p"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
     
    	<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" />
     
    	<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    		<property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
    		<property name="url" value="jdbc:hsqldb:hsql://localhost:9001"/>
    		<property name="username" value="sa"/>
    	</bean>
     
    	<bean id="mySessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    		<property name="dataSource" ref="myDataSource" />
    		<property name="annotatedClasses">
    			<list>
    				<value>com.vaannila.domain.User</value>
    			</list>
    		</property>
    		<property name="hibernateProperties">
    			<props>
    				<prop key="hibernate.connection.pool_size">1</prop>			
    				<prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
    				<prop key="hibernate.show_sql">true</prop>
    				<prop key="hibernate.hbm2ddl.auto">create</prop>
    			</props>
    		</property>
    	</bean>
     
    	<bean id="myUserDAO" class="com.vaannila.dao.UserDAOImpl">
    		<property name="sessionFactory" ref="mySessionFactory"/>
    	</bean>
     
    	<bean name="/user/*.htm" class="com.vaannila.web.UserController" >
    		<property name="userDAO" ref="myUserDAO" />
    	</bean>
     
    </beans>

    User.java :

    package com.vaannila.domain;
     
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.Id;
    import javax.persistence.Table;
     
    @Entity
    @Table(name="USER")
    public class User {
     
    	private Long id;
    	private String name;
    	private String password;
    	private String gender;
    	private String country;
    	private String aboutYou;
    	private String[] community;
    	private Boolean mailingList;
     
    	@Id
    	@GeneratedValue
    	@Column(name="USER_ID")
    	public Long getId() {
    		return id;
    	}
    	public void setId(Long id) {
    		this.id = id;
    	}
     
    	@Column(name="USER_NAME")
    	public String getName() {
    		return name;
    	}
    	public void setName(String name) {
    		this.name = name;
    	}
     
    	@Column(name="USER_PASSWORD")
    	public String getPassword() {
    		return password;
    	}
    	public void setPassword(String password) {
    		this.password = password;
    	}
     
    	@Column(name="USER_GENDER")
    	public String getGender() {
    		return gender;
    	}
    	public void setGender(String gender) {
    		this.gender = gender;
    	}
     
    	@Column(name="USER_COUNTRY")
    	public String getCountry() {
    		return country;
    	}
    	public void setCountry(String country) {
    		this.country = country;
    	}
     
    	@Column(name="USER_ABOUT_YOU")
    	public String getAboutYou() {
    		return aboutYou;
    	}
    	public void setAboutYou(String aboutYou) {
    		this.aboutYou = aboutYou;
    	}
     
    	@Column(name="USER_COMMUNITY")
    	public String[] getCommunity() {
    		return community;
    	}
    	public void setCommunity(String[] community) {
    		this.community = community;
    	}
     
    	@Column(name="USER_MAILING_LIST")
    	public Boolean getMailingList() {
    		return mailingList;
    	}
    	public void setMailingList(Boolean mailingList) {
    		this.mailingList = mailingList;
    	}
     
    }

    UserDAOImpl.java :

    package com.vaannila.dao;
     
    import java.util.List;
    import org.hibernate.SessionFactory;
    import org.springframework.orm.hibernate3.HibernateTemplate;
    import com.vaannila.domain.User;
     
    public class UserDAOImpl implements UserDAO {
     
    	private HibernateTemplate hibernateTemplate;
     
    	public void setSessionFactory(SessionFactory sessionFactory) {
    		this.hibernateTemplate = new HibernateTemplate(sessionFactory);
    	}
     
    	@Override
    	public void saveUser(User user) {
    		hibernateTemplate.saveOrUpdate(user);
    	}
     
    	@Override
    	@SuppressWarnings("unchecked")
    	public List<User> listUser() {
    		return hibernateTemplate.find("from User");
    	}
     
    }

    UserDAO.java


    package com.vaannila.dao;
     
    import java.util.List;
    import com.vaannila.domain.User;
     
    public interface UserDAO {
     
    	public void saveUser(User user) ;
    	public List<User> listUser() ;
    }

    UserController.java :
    package com.vaannila.dao;
     
    import java.util.List;
    import com.vaannila.domain.User;
     
    public interface UserDAO {
     
    	public void saveUser(User user) ;
    	public List<User> listUser() ;
    }


    UserForm.jsp(front end) and redirect.jsp (starts app)

    HERE IS THE ERROR LOG ! :

    HTTP Status 500

    type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    javax.servlet.ServletException: Servlet.init() for servlet dispatcher threw exception
    org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:102)
    org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:298)
    org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:859)
    org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(Http11Protocol.java:588)
    org.apache.tomcat.util.net.JIoEndpoint$Worker.run( JIoEndpoint.java:489)
    java.lang.Thread.run(Thread.java:662)

    root cause

    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'mySessionFactory' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Invocation of init method failed; nested exception is org.springframework.beans.BeanInstantiationExcepti on: Could not instantiate bean class [org.hibernate.cfg.AnnotationConfiguration]: Constructor threw exception; nested exception is java.lang.NoSuchFieldError: INSTANCE
    org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1420)
    org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:519)
    org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:456)
    org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 91)
    org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:222)
    org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:288 )
    org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:190)
    org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:563)
    org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:895)
    org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:425)
    org.springframework.web.servlet.FrameworkServlet.c reateWebApplicationContext(FrameworkServlet.java:4 42)
    org.springframework.web.servlet.FrameworkServlet.c reateWebApplicationContext(FrameworkServlet.java:4 58)
    org.springframework.web.servlet.FrameworkServlet.i nitWebApplicationContext(FrameworkServlet.java:339 )
    org.springframework.web.servlet.FrameworkServlet.i nitServletBean(FrameworkServlet.java:306)
    org.springframework.web.servlet.HttpServletBean.in it(HttpServletBean.java:127)
    javax.servlet.GenericServlet.init(GenericServlet.j ava:212)
    org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:102)
    org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:298)
    org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:859)
    org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(Http11Protocol.java:588)
    org.apache.tomcat.util.net.JIoEndpoint$Worker.run( JIoEndpoint.java:489)
    java.lang.Thread.run(Thread.java:662)

    root cause
    org.springframework.beans.BeanInstantiationExcepti on: Could not instantiate bean class [org.hibernate.cfg.AnnotationConfiguration]: Constructor threw exception; nested exception is java.lang.NoSuchFieldError: INSTANCE
    org.springframework.beans.BeanUtils.instantiateCla ss(BeanUtils.java:141)
    org.springframework.beans.BeanUtils.instantiateCla ss(BeanUtils.java:104)
    org.springframework.orm.hibernate3.LocalSessionFac toryBean.newConfiguration(LocalSessionFactoryBean. java:818)
    org.springframework.orm.hibernate3.LocalSessionFac toryBean.buildSessionFactory(LocalSessionFactoryBe an.java:549)
    org.springframework.orm.hibernate3.AbstractSession FactoryBean.afterPropertiesSet(AbstractSessionFact oryBean.java:211)
    org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods(Abstr actAutowireCapableBeanFactory.java:1477)
    org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1417)
    org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:519)
    org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:456)
    org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 91)
    org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:222)
    org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:288 )
    org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:190)
    org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:563)
    org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:895)
    org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:425)
    org.springframework.web.servlet.FrameworkServlet.c reateWebApplicationContext(FrameworkServlet.java:4 42)
    org.springframework.web.servlet.FrameworkServlet.c reateWebApplicationContext(FrameworkServlet.java:4 58)
    org.springframework.web.servlet.FrameworkServlet.i nitWebApplicationContext(FrameworkServlet.java:339 )
    org.springframework.web.servlet.FrameworkServlet.i nitServletBean(FrameworkServlet.java:306)
    org.springframework.web.servlet.HttpServletBean.in it(HttpServletBean.java:127)
    javax.servlet.GenericServlet.init(GenericServlet.j ava:212)
    org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:102)
    org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:298)
    org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:859)
    org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(Http11Protocol.java:588)
    org.apache.tomcat.util.net.JIoEndpoint$Worker.run( JIoEndpoint.java:489)
    java.lang.Thread.run(Thread.java:662)

    root cause java.lang.NoSuchFieldError: INSTANCE
    org.hibernate.type.BasicTypeRegistry.<init>(BasicT ypeRegistry.java:94)
    org.hibernate.type.TypeResolver.<init>(TypeResolve r.java:59)
    org.hibernate.cfg.Configuration.<init>(Configurati on.java:250)
    org.hibernate.cfg.Configuration.<init>(Configurati on.java:302)
    org.hibernate.cfg.AnnotationConfiguration.<init>(A nnotationConfiguration.java:108)
    sun.reflect.NativeConstructorAccessorImpl.newInsta nce0(Native Method)
    sun.reflect.NativeConstructorAccessorImpl.newInsta nce(NativeConstructorAccessorImpl.java:39)
    sun.reflect.DelegatingConstructorAccessorImpl.newI nstance(DelegatingConstructorAccessorImpl.java:27)
    java.lang.reflect.Constructor.newInstance(Construc tor.java:513)
    org.springframework.beans.BeanUtils.instantiateCla ss(BeanUtils.java:126)
    org.springframework.beans.BeanUtils.instantiateCla ss(BeanUtils.java:104)
    org.springframework.orm.hibernate3.LocalSessionFac toryBean.newConfiguration(LocalSessionFactoryBean. java:818)
    org.springframework.orm.hibernate3.LocalSessionFac toryBean.buildSessionFactory(LocalSessionFactoryBe an.java:549)
    org.springframework.orm.hibernate3.AbstractSession FactoryBean.afterPropertiesSet(AbstractSessionFact oryBean.java:211)
    org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods(Abstr actAutowireCapableBeanFactory.java:1477)
    org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1417)
    org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:519)
    org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:456)
    org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 91)
    org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:222)
    org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:288 )
    org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:190)
    org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:563)
    org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:895)
    org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:425)
    org.springframework.web.servlet.FrameworkServlet.c reateWebApplicationContext(FrameworkServlet.java:4 42)
    org.springframework.web.servlet.FrameworkServlet.c reateWebApplicationContext(FrameworkServlet.java:4 58)
    org.springframework.web.servlet.FrameworkServlet.i nitWebApplicationContext(FrameworkServlet.java:339 )
    org.springframework.web.servlet.FrameworkServlet.i nitServletBean(FrameworkServlet.java:306)
    org.springframework.web.servlet.HttpServletBean.in it(HttpServletBean.java:127)
    javax.servlet.GenericServlet.init(GenericServlet.j ava:212)
    org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:102)
    org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:298)
    org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:859)
    org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(Http11Protocol.java:588)
    org.apache.tomcat.util.net.JIoEndpoint$Worker.run( JIoEndpoint.java:489)
    java.lang.Thread.run(Thread.java:662)
    note The full stack trace of the root cause is available in the Apache Tomcat/6.0.32 logs.

    Apache Tomcat/6.0.32

Similar Threads

  1. Is it possible to instantiate an interafce ?
    By Learner in forum Object Oriented Programming
    Replies: 7
    Last Post: September 2nd, 2011, 12:10 PM
  2. Instantiation of bean failed
    By peejayuk in forum Member Introductions
    Replies: 1
    Last Post: August 15th, 2011, 02:35 PM
  3. [SOLVED] What do I need to do to use a bean in Netbeans 7 apart from defining it?
    By Lord Voldemort in forum JavaServer Pages: JSP & JSTL
    Replies: 2
    Last Post: July 31st, 2011, 12:29 AM
  4. converting HashMap to a Bean
    By achsu in forum Collections and Generics
    Replies: 0
    Last Post: February 2nd, 2011, 09:13 PM
  5. [SOLVED] instantiate problems
    By jamal in forum Object Oriented Programming
    Replies: 9
    Last Post: September 13th, 2010, 06:08 PM