5
The name of the class containing the SessionFactory
is DataProvider
and has the following implementation:
@Resource(name="sessionFactory")
protected SessionFactory factory;
protected Class<E> entity;
protected String tableName;
public DataProvider(Class e) {
this.entity = e;
this.tableName = entity.getAnnotation(Table.class).name();
}
@Transactional(readOnly = true)
public List<E> getAll() {
Session s = factory.getCurrentSession(); // A exceção acontece aqui.
return s.createQuery("FROM " + tableName ).list();
}
The bean with the configuration of the SessionFactory
is:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="models"/>
<property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
</bean>
I’m getting NullPointerException
in the commented line. The question is: am I doing something wrong or still missing some configuration?
This XML is the
persistence.xml
or is another?– Leonel Sanches da Silva
The class this code is in is a Bean managed by Spring?
– utluiz
@Ciganomorrisonmendez XML is from Spring.
– utluiz
You can update your reply to have the
persistence.xml
+ the complete Bean code + the part of XML that configures the Bean injections?– Leonel Sanches da Silva
@Ciganomorrisonmendez is the
applicationContext.xml
– Filipe
And the package your classes are in is just
models
even?– Miguel Cartagena
@Miguelcartagena Yes!
– Filipe
What version of Spring are you using?
– user4429