Hi,
I have a question.
I have a generic DAO template class and I use it for all my tables in my database.
The declaration is like that.
@Repository
public final class GenericHibernateDao<T, ID extends Serializable>
implements GenericDao<T, ID>
I have something like that in applicationContext.xml
<!-- Generic Dao -->
<bean id="counterpartSampleDao"
class="sgcib.ged.testxfire.core.persistence.hibern ate.dao.GenericHibernateDao">
<property name="persistentClass">
<bean id="counterpartSampleClass" class="java.lang.Class"
factory-method="forName">
<constructor-arg>
<value>sgcib.ged.testxfire.core.persistence.hibern ate.domain.CounterpartSample</value>
</constructor-arg>
</bean>
</property>
</bean>
<bean id="dealSampleDao"
class="sgcib.ged.testxfire.core.persistence.hibern ate.dao.GenericHibernateDao">
<property name="persistentClass">
<bean id="dealSampleClass" class="java.lang.Class"
factory-method="forName">
<constructor-arg>
<value>sgcib.ged.testxfire.core.persistence.hibern ate.domain.DealSample</value>
</constructor-arg>
</bean>
</property>
</bean>
<bean id="productSampleDao"
class="sgcib.ged.testxfire.core.persistence.hibern ate.dao.GenericHibernateDao">
<property name="persistentClass">
<bean id="productSampleClass" class="java.lang.Class"
factory-method="forName">
<constructor-arg>
<value>sgcib.ged.testxfire.core.persistence.hibern ate.domain.ProductSample</value>
</constructor-arg>
</bean>
</property>
</bean-->
I want to wire them with @Autowire in my Business Components but it not possible because I have more than one bean for this generic Dao class (it is normal because @Autowired wire by type).
I want to know is it possible to wire by type and if there is more than one bean, to wire by name. I think it coud be a very cool feature.
It is like @Configurable annotation
(autowire=Autowire.BY_NAME)
(autowire=Autowire.BY_TYPE)
and add something like
(autowire=Autowire.BY_TYPE_AND_BY_NAME_IF_NECESSAR Y)
(the last constant is ugly, but I'm very bad to find good short name)
The last feature can also be add fto the @Configurable annotation.


Reply With Quote