81,095
社区成员
发帖
与我相关
我的任务
分享
12:15:34,250 INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured
java.lang.UnsupportedOperationException: The user must supply a JDBC connection
at net.sf.Hibernate.connection.UserSuppliedConnectionProvider.getConnection (UserSuppliedConnectionProvider.java:32)
at net.sf.Hibernate.impl.BatcherImpl.openConnection(BatcherImpl.java:289)
at net.sf.Hibernate.impl.SessionImpl.connect(SessionImpl.java:3361)
at net.sf.Hibernate.impl.SessionImpl.connection(SessionImpl.java:3321)
at net.sf.Hibernate.impl.BatcherImpl.prepareQueryStatement(BatcherImpl.java:66)
at net.sf.Hibernate.loader.Loader.prepareQueryStatement(Loader.java:779)
at net.sf.Hibernate.hql.QueryTranslator.iterate(QueryTranslator.java:864)
at net.sf.Hibernate.impl.SessionImpl.iterate(SessionImpl.java:1618)
at net.sf.Hibernate.impl.QueryImpl.iterate(QueryImpl.java:27)
at com.Hibernate.person.TestQueryPerson.main(TestQueryPerson.java:28)
Exception in thread "main"
答:修改main函数,为该程序指定配置文件即可。
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="connection.url">
jdbc:mysql://localhost:3306/
</property>
<property name="connection.username">root</property>
<property name="connection.password"></property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="myeclipse.connection.profile">mysql</property>
<mapping resource="com/fjr/entity/Users.hbm.xml" />
</session-factory>
</hibernate-configuration>
<?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:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
">
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="com.mysql.jdbc.Driver">
</property>
<property name="url" value="jdbc:mysql://localhost:3306/"></property>
<property name="username" value="root"></property>
<property name="password" value=""></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/fjr/entity/Users.hbm.xml</value>
</list>
</property>
</bean>
<!-- 事务管理 -->
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<aop:config>
<aop:pointcut expression="execution(* com.fjr.biz.impl.*.*(..))" id="aoppointcut"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="aoppointcut"/>
</aop:config>
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="*" propagation="SUPPORTS" read-only="true"/>
</tx:attributes>
</tx:advice>
<bean id="userDao" class="com.fjr.dao.impl.UserDao">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="userBiz" class="com.fjr.biz.impl.UserBiz">
<property name="userDao" ref="userDao"></property>
</bean>
<bean id="userActioin" class="com.fjr.entity.Users">
<property name="userBiz" ref="userBiz"></property>
</bean>
</beans>