ssh整合之整合hibernate和spring

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_36084681/article/details/80481908

配置SessionFactory在applicationContext.xml中

<!-- 将SessionFactory配置到spring容器中 -->

<bean name="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean" >
<!-- 将连接池注入到sessionFactory, hibernate会通过连接池获得连接 -->
<property name="dataSource" ref="dataSource" ></property>
<!-- 配置hibernate基本信息 -->
<property name="hibernateProperties">
<props>
<!--  必选配置 -->
<!-- <prop key="hibernate.connection.driver_class" >com.mysql.jdbc.Driver</prop>
<prop key="hibernate.connection.url" >jdbc:mysql:///crm_32</prop>
<prop key="hibernate.connection.username" >root</prop>

<prop key="hibernate.connection.password" >1234</prop> -->



<prop key="hibernate.dialect" >org.hibernate.dialect.MySQLDialect</prop>

<!--  可选配置 -->
<prop key="hibernate.show_sql" >true</prop>
<prop key="hibernate.format_sql" >true</prop>
<prop key="hibernate.hbm2ddl.auto" >update</prop>
</props>
</property>
<!-- 引入orm元数据,指定orm元数据所在的包路径,spring会自动读取包中的所有配置 -->
<property name="mappingDirectoryLocations" value="classpath:cn/itcast/domain" ></property>

</bean>


如果配置了连接池,那么数据库连接信息就可以不要了


展开阅读全文

ssh整合hibernate问题

04-10

rn[code=java]10-Apr-2017 22:08:53.484 严重 [http-apr-8080-exec-5] org.apache.struts2.dispatcher.Dispatcher.error Exception occurred during processing request: User is not mapped [from User where username=aaaa]rn org.hibernate.hql.internal.ast.QuerySyntaxException: User is not mapped [from User where username=aaaa]rn at org.hibernate.hql.internal.ast.QuerySyntaxException.generateQueryException(QuerySyntaxException.java:96)rn at org.hibernate.QueryException.wrapWithQueryString(QueryException.java:120)rn at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:234)rn at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:158)rn at org.hibernate.engine.query.spi.HQLQueryPlan.(HQLQueryPlan.java:131)rn at org.hibernate.engine.query.spi.HQLQueryPlan.(HQLQueryPlan.java:93)rn at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:167)rn at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:301)rn at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:236)rn at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1800)rn at cn.itcast.shop.user.dao.UserDao.findByUsername(UserDao.java:19)rn at cn.itcast.shop.user.service.UserService.findByUsername(UserService.java:22)rn at cn.itcast.shop.user.service.UserService$$FastClassBySpringCGLIB$$5f146785.invoke()rn at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)rn at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:708)rn at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)rn at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:98)rn at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:262)rn at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)rn at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)rn at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:644)rn at cn.itcast.shop.user.service.UserService$$EnhancerBySpringCGLIB$$94b2a476.findByUsername()rn at cn.itcast.shop.user.action.UserAction.findByName(UserAction.java:48)rn[/code]rnrn网上查的错误,hql写错,但是我看了,没有错 论坛

没有更多推荐了,返回首页