Announcement Announcement Module
Collapse
No announcement yet.
Wiring up spring and hibernate with annotations: entity not loading Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Wiring up spring and hibernate with annotations: entity not loading

    Hi,

    I'm trying to wire up spring and hibernate using Spring 3.0.1 and Hibernate 3.6.3. (This is my first time using either of these versions.)

    Here is my config:
    applicationContext-dao-hbm.xml
    Code:
    <beans>
    
       <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
          <property name="dataSource" ref="dataSource" />
          <property name="annotatedClasses">
             <list>
                <value>fas.admincmp.course_manager.model.login.UserDetails</value>
             </list>
          </property>
          <property name="hibernateProperties">
             <props>
                <prop key="hibernate.dialect"> org.hibernate.dialect.Oracle9Dialect</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.hbm2ddl.auto">create</prop>
             </props>
          </property>
        </bean>
        
        <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
          <constructor-arg>
             <ref bean="sessionFactory" />
          </constructor-arg>
        </bean>
    
    </beans>
    My Pojo:
    Code:
    package fas.admincmp.course_manager.model.login;
    
    import javax.persistence.Column;
    import javax.persistence.Id;
    
    import org.hibernate.annotations.Entity;
    import org.hibernate.annotations.Table;
    
    @Entity
    @Table(appliesTo="user_details")
    public class UserDetails {
    	
    	String univId;
    
    	@Id
    	public String getUnivId()
       {
       	return univId;
       }
    
    }
    My test method:
    Code:
       @Test
    	public void testConfig() throws SQLException
    	{
    		sessionFactory.getCurrentSession().get( UserDetails.class, "123456789") ;
    	}
    And the error I'm getting:

    Code:
    org.hibernate.MappingException: Unknown entity: fas.admincmp.course_manager.model.login.UserDetails
    	at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:693)
    	at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:92)
    	at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:1090)
    	at org.hibernate.impl.SessionImpl.get(SessionImpl.java:1005)
    	at org.hibernate.impl.SessionImpl.get(SessionImpl.java:998)
    	at fas.admincmp.course_manager.model.HibernateUserDetailsTest.testConfig(HibernateUserDetailsTest.java:83)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	at java.lang.reflect.Method.invoke(Unknown Source)
    	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    	at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
    	at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82)
    	at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
    	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)
    	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
    	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
    	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
    	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
    	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Working...
X