Announcement Announcement Module
Collapse
No announcement yet.
Hibernate annotaion Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Hibernate annotaion

    Hi...
    Try to make a connection with spring and hibernate throws the following error:
    No unique bean of type [org.hibernate.SessionFactory is defined: Unsatisfied dependency of type [interface org.hibernate.SessionFactory]: expected at least 1 matching bean

    my servlet
    Code:
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    	xsi:schemaLocation="
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        ">
    
    	<context:component-scan base-package="example.jersey.spring" />
    	<context:annotation-config />
    
    	<import resource="classpath:springmvc-resteasy.xml" />
    
    
    	
    	<bean id="dataSource"
    		class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    		<property name="driverClassName">
    			<value>org.hsqldb.jdbcDriver</value>
    		</property>
    		<property name="url">
    			<value>jdbc:hsqldb:file:c:/tmp/Customers;shutdown=true
    			</value>
    		</property>
    		<property name="username">
    			<value>sa</value>
    		</property>
    		<property name="password">
    			<value></value>
    		</property>
    	</bean>
    
     
    	<bean id="sessionFactory"
    	class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    	<property name="dataSource" ref="dataSource" />
    	
    
    	<property name="annotatedClasses">
    		<list>
    			<value>example.jersey.spring.Customer</value>			
    		</list>
    	</property>
    	<property name="hibernateProperties">
    		<value>
    			hibernate.hbm2ddl.auto=create
    			hibernate.dialect=org.hibernate.dialect.HSQLDialect
    			hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
          </value>
    	</property>
    </bean>
    myConnection class
    Code:
    public class CustomerDaoHibernateImpl extends HibernateDaoSupport implements
    		CustomerDao {
    
    	@Autowired
    	private SessionFactory sessionFactory;
    	
    	public Customer findCustomerById(int id) {
    		// TODO Auto-generated method stub
    		return null;
    	}
    
    	public Collection<Customer> getCustomers() {
    		// TODO Auto-generated method stub
    		return null;
    	}
    
    	public void save(Customer customer) {
    		// TODO Auto-generated method stub
    		
    	}
    	public String toString() {
    		
    		// TODO Auto-generated method stub
    		return "toString";
    	}
    	}
    If i remove the two lines
    Code:
    @Autowired
    	private SessionFactory sessionFactory;
    then it works - but no connection
    Last edited by kroschel; Jun 12th, 2009, 09:01 AM. Reason: remove comments

  • #2
    the answer of my problem:

    Code:
    @Autowired
    	public CustomerDaoHibernateImpl(SessionFactory sessionFactory) {
    		setSessionFactory(sessionFactory);
    	}

    Comment

    Working...
    X