English 中文(简体)
春季3 说明 - HibernateDaoSupport - 保存者会议
原标题:Spring 3 Annotations - HibernateDaoSupport - Repository Requires Session Factory

我正在破例说:

java.lang.IllegalArgumentException: sessionFactory or hibernateTemplate is required

在试图使用<条码>@ 交存时 DaoSupport 班。 错误信息是直截了当的,为了创建保存机构,它需要一个实践。 然而,我已经在我的《冲绳法》中界定了一家工厂:

<!-- Hibernate -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="dashDataSource" />
        <property name="annotatedClasses">
            <list>
                <value>com.mycomp.myapp.Category</value>
            </list>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
            </props>
        </property>
    </bean>

因此,我不敢肯定,如何让存放处保存它所需要的会议惯例,而同时又要创建它所驱动的传票人。

 @Autowired
    protected HibernateTemplate createHibernateTemplate(SessionFactory sessionFactory) {
        return super.createHibernateTemplate(sessionFactory);
    }

但是,这并不能解决问题,可能是因为存放处需要财产在即时进行,而不仅仅是在采取行动时。 不幸的是,我不知道如何解决这一问题,因为没有建筑或初始化方法以“Autowired annotation”取代。

我进行了检查,以确保会议楼群的建立,可以自动连接,这是罚款。

最佳回答

<代码>HibernateDaoSupport >通过<代码>>setFactory提供。 但是,setSessionFactory(>>> ,/code>,因此,你可以先于填入<>@Autowired annotation>。 但是,你可以将<条码>@Autowired应用于任意方法,并打电话<条码>。

@Autowired
public void init(SessionFactory factory) {
    setSessionFactory(factory);
}
问题回答

您也可通过使用<条码>@Qualifier通知来界定你想要使用的哪一个车间(如果你有一个以上的话):

@Autowired
public MyClassImpl(@Qualifier("myOtherSessionFactory") SessionFactory sessionFactory) {
    setSessionFactory(sessionFactory);
}

也可通过扩大<代码>在数据来源之间展开辩论。 摘要RoutingDataSource 。 见





相关问题
Multiple Hibernate instances using C3P0

I am facing a weird problem and it seems to be c3p0 related. I am starting two instances of an app in the same java vm which interact with each other. After some operations "APPARENT DEADLOCK" ...

Hibernate vs Ibatis caching

We can speed up a hibernate app easyly with 2nd level cache using infinispan or ehcache/terracotta,... but ibatis only have a simple interface to implement for caching. And hibernate knows more ...

Using annotations to implement a static join in hibernate

I m relatively new to hibernate and was wondering if someone could help me out. While I have no issues implementing a normal join on multiple columns in hibernate using the @JoinColumns tag, I m ...

Hibernate query with fetch question

I have a 2 entities in a One-To-Many relationship: OfficeView.java: public class OfficeView implements java.io.Serializable { private Integer officeId; private String addr1; private ...

hibernate interceptors : afterTransactionCompletion

I wrote a Hibernate interceptor : public class MyInterceptor extends EmptyInterceptor { private boolean isCanal=false; public boolean onSave(Object entity, Serializable arg1, Object[] arg2, String[]...

How to prevent JPA from rolling back transaction?

Methods invoked: 1. Struts Action 2. Service class method (annotated by @Transactional) 3. Xfire webservice call Everything including struts (DelegatingActionProxy) and transactions is configured ...

Hibernate/GORM: collection was not processed by flush()

I have an integration test in my Grails application that fails when I try to save an entity of type Member invitingMember.save(flush: true) This raises the following exception org.hibernate....

Hibernate Criteria API equivalent for "elements()"

Is it possible to implement the following query using Criteria API? select order from ORDER as order,ITEM as item where item.itemID like ITM_01 and item in elements(order.items)

热门标签