Results 1 to 4 of 4

Thread: Error in sessionFactory bean creation

  1. #1
    Join Date
    Feb 2006
    Posts
    2

    Default Error in sessionFactory bean creation

    I'm new to springframework and I'm trying to follow the sample program from "Spring: A Developer's Notebook".

    I get an error in my spring configuration file that says it cannot find the "id" field to create the sessionFactory bean. I don't understand what this means.

    Code:
    Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [RentABike-context.xml]: Initialization of bean failed; nested exception is org.hibernate.PropertyNotFoundException: field not found: id
    org.hibernate.PropertyNotFoundException: field not found: id
    	at org.hibernate.property.DirectPropertyAccessor.getField(DirectPropertyAccessor.java:97)
    	at org.hibernate.property.DirectPropertyAccessor.getField(DirectPropertyAccessor.java:104)
    	at org.hibernate.property.DirectPropertyAccessor.getGetter(DirectPropertyAccessor.java:112)
    	at org.hibernate.util.ReflectHelper.getter(ReflectHelper.java:89)
    	at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:77)
    	at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:276)
    	at org.hibernate.cfg.HbmBinder.bindSimpleId(HbmBinder.java:403)
    	at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:336)
    	at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:275)
    	at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:146)
    	at org.hibernate.cfg.Configuration.add(Configuration.java:385)
    	at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:426)
    	at org.springframework.orm.hibernate3.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:654)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1059)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:363)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:226)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:147)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:269)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:320)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:87)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:72)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:63)
    	at spring.RentABikeAssembler.main(RentABikeAssembler.java:10)
    The spring configuration file is as follows:
    Code:
    <beans>
    	<bean id="dataSource"
    		class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    		<property name="driverClassName">
    			<value>org.hsqldb.jdbcDriver</value>
    		</property>
    		<property name="url">
    			<value>jdbc:hsqldb:hsql://localhost</value>
    		</property>
    		<property name="username">
    			<value>sa</value>
    		</property>
    	</bean>
    
    	<bean id="rentaBike" class="spring.HibRentABike">
    		<property name="storeName">
    			<value>"Bruce's Bikes"</value>
    		</property>
    		<property name="sessionFactory">
    			<ref local="sessionFactory" />
    		</property>
    	</bean>
    
    	<bean id="sessionFactory"
    		class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    		<property name="dataSource">
    			<ref local="dataSource" />
    		</property>
    		<property name="mappingResources">
    			<list>
    				<value>spring/Bike.hbm.xml</value>
    			</list>
    		</property>
    		<property name="hibernateProperties">
    			<props>
    				<prop key="hibernate.dialect">
    					org.hibernate.dialect.HSQLDialect
    				</prop>
    			</props>
    		</property>
    	</bean>
    
    	<bean id="commandLineView" class="spring.CommandLineView">
    		<property name="rentaBike">
    			<ref bean="rentaBike" />
    		</property>
    	</bean>
    
    </beans>
    Note that I only want to output the results to the console. I haven't integrated it yet with tomcat or other web UI. What do I need to change in the spring config file to fix this.

    Thanks!
    When all else fails - fresh tactics!

  2. #2
    Join Date
    Aug 2004
    Posts
    1,905

    Default

    Without looking too closely

    This exception is (what|similiar to the one) you get if you have defined an property in the mapping file which doesn't exist on the object model.

    I would check your mapping files (Bike.hbm.xml) and ensure that there actually is an "id" on the domain model.

  3. #3
    Join Date
    Feb 2006
    Posts
    2

    Default

    How embarassing!!!

    I forgot to add an id member to my Bike class.
    Thanks!
    When all else fails - fresh tactics!

  4. #4
    Join Date
    Aug 2004
    Posts
    1,905

    Default

    Happens to us all; how do you think I recognised the exception

Posting Permissions

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