67,514
社区成员
发帖
与我相关
我的任务
分享
<?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="hbm2ddl.auto">update</property>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="connection.url">
jdbc:mysql://localhost:3306/mydb
</property>
<property name="connection.username">root</property>
<property name="connection.password">123456</property>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="myeclipse.connection.profile">
localhost_mysql_mydb
</property>
<mapping resource="com/pojo/User.hbm.xml" />
<mapping resource="com/pojo/Rolegroup.hbm.xml" />
<mapping resource="com/pojo/Menu.hbm.xml" />
<mapping resource="com/pojo/Role.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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<context:component-scan base-package="com.controller,com.dao,com.service" />
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation"
value="classpath:hibernate.cfg.xml">
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<!-- 配置视图解析器 -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
@Repository("这里填写注入的ID")
public class UserDao extends HibernateDaoSupport{
@Resource
public void setMySessionFactory(SessionFactory sessionFactory){
super.setSessionFactory(sessionFactory);
}
@SuppressWarnings("unchecked")
public User getUserbyId(String userId) {
SQLQuery query=this.getSession().createSQLQuery("select * from User where userid=?");
query.addEntity(User.class);
query.setString(0, userId);
List<User> resultList=query.list();
if(resultList != null ){
User results = resultList.get(0);
return results;
}
return null;
}
}
@Repository("userDao")
public class UserDao extends HibernateDaoSupport{
@Resource
public void setMySessionFactory(SessionFactory sessionFactory){
super.setSessionFactory(sessionFactory);
}
@SuppressWarnings("unchecked")
public User getUserbyId(String userId) {
SQLQuery query=this.getSession().createSQLQuery("select * from User where userid=?");
query.addEntity(User.class);
query.setString(0, userId);
List<User> resultList=query.list();
if(resultList != null ){
User results = resultList.get(0);
return results;
}
return null;
}
}
我要怎么样用配置的两个sessionFactory???
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>
<bean id="sessionFactory2" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>classpath:hibernate2.cfg.xml</value>
</property>
</bean>