为什么直接调用hibernate的dao中的方法会出现nullpointerexception
publicclassTest{publicstaticvoidmain(String[]args){LzwDAOl=newLzwDAO();Lzwlzw=l.findB...
public class Test {
public static void main(String[] args) {
LzwDAO l = new LzwDAO();
Lzw lzw = l.findById((short)7521);
System.out.println(lzw.toString());
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation" value="classpath:hibernate.cfg.xml">
</property>
</bean>
<bean id="LzwDAO" class="com.lzw001.domain.LzwDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean></beans> 展开
public static void main(String[] args) {
LzwDAO l = new LzwDAO();
Lzw lzw = l.findById((short)7521);
System.out.println(lzw.toString());
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation" value="classpath:hibernate.cfg.xml">
</property>
</bean>
<bean id="LzwDAO" class="com.lzw001.domain.LzwDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean></beans> 展开
1个回答
推荐于2016-05-26
展开全部
正规写法DAO里面应该是接口吧。直接调用接口的话,你觉得真的没问题。没记错的话应该还有一个实现类的。如果是使用DAO调用的话应该是
LzwDAO l = new LzwDAOImpl();
其中LzwDAOImpl()是实现类。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询