我有一个DispactherServlet.xml
文件,其hibernate文件配置为
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="mappingResources">
<list>
<value>com/dibya/hbm/resource/model.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.username">root</prop>
<prop key="hibernate.password"></prop>
<prop key="hibernate.url">jdbc:mysql://localhost/test</prop>
<prop key="hibernate.driver_class">com.mysql.jdbc.Driver</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
</props>
</property>
</bean>
<bean id = "hibernateTemplate" class = "org.springframework.orm.hibernate3.HibernateTemplate">
<property name = "persister">
<ref bean = "sessionFactory"/>
</property>
</bean>
在我的控制器中,我有
@RequestMapping(value = "Hello.htm")
public String HelloWorld(Model model) {
boolean is = persister.isAllowCreate();
Person person = new Person();
person.setName("dibya");
persister.saveOrUpdate(person);
System.out.println("This is called"+is);
return "HelloWorld";
}
我收到此错误消息:
HTTP Status 500 - Request processing failed; nested exception is java.lang.UnsupportedOperationException: The user must supply a JDBC connection
请告诉我忘记添加的内容。
答案 0 :(得分:4)
您的hibernate配置文件使用了错误的参数名称。正确的参数名称如下:
hibernate.connection.driver_class
hibernate.connection.url
hibernate.connection.username
hibernate.connection.password
hibernate.dialect
hibernate.show_sql
更正您的参数名称,然后重试。
编辑:请参阅此链接以获取参数名称的详细列表:http://docs.jboss.org/hibernate/core/3.3/reference/en/html/session-configuration.html
答案 1 :(得分:0)
您可以这样配置:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="hibernateProperties">
<props>
<prop key="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</prop>
<prop key="hibernate.connection.url">jdbc:hsqldb:file:/local/hsqldb</prop>
<prop key="hibernate.connection.username">sa</prop>
<prop key="hibernate.connection.password"></prop>
<prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
<prop key="hibernate.show_sql">${gloss.database.hibernate.show_sql}</prop>
<prop key="hibernate.order_inserts">true</prop>
<prop key="hibernate.order_updates">true</prop>
<prop key="hibernate.jdbc.batch_size">100</prop>
<prop key="hibernate.hbm2ddl.auto">validate</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/core/domain/User.hbm.xml</value>
</list>
</property>
</bean>