高分求教……org.hibernate.hql.ast.QuerySyntaxException: User is not mapped [from User]
org.springframework.orm.hibernate3.HibernateQueryException:Userisnotmapped[fromUser];...
org.springframework.orm.hibernate3.HibernateQueryException: User is not mapped [from User]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: User is not mapped [from User]
org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:657)
org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:921)
org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:913)
com.test.model.UserAction.execute(UserAction.java:54)
……
beans.xml中是:<context:annotation-config />
<context:component-scan base-package="com.test" />
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="net.sourceforge.jtds.jdbc.Driver" />
<property name="url"
value="jdbc:jtds:sqlserver://localhost:1433;databasename=test" />
<property name="username" value="sa" />
<property name="password" value="hunter" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan">
<list>
<value>com.test.model</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.SQLServerDialect
hibernate.show_sql=true
hibernate.hbm2ddl.auto=update
</value>
</property>
</bean>
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="myTxManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:annotation-driven transaction-manager="myTxManager" />
struts.xml如下:
<struts>
<package name="struts2_hibernate_spring" extends="struts-default">
<action name="user" class="com.test.model.UserAction">
<result name="success">/success.jsp</result>
<result name="fail">/fail.jsp</result>
</action>
</package>
</struts>
……
.class类如下:
public String execute() throws Exception {
if(password.equals(password2)){
User user = new User();
user.setUsername(username);
user.setPassword(password);
hibernateTemplate.save(user);
return hibernateTemplate.find("from User").size()>0?"success":"fail";
}
return "fail";
}
不是我想写那么多,实在是没有办法了,第一次用struts2\hibernate\spring整合后出现的这个问题,我一整天了都没得解决,hibernateTemplate.save()可以,但hibernateTemplate.find()就不得了,把我的分拿去吧
??? 展开
org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:657)
org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:921)
org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:913)
com.test.model.UserAction.execute(UserAction.java:54)
……
beans.xml中是:<context:annotation-config />
<context:component-scan base-package="com.test" />
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="net.sourceforge.jtds.jdbc.Driver" />
<property name="url"
value="jdbc:jtds:sqlserver://localhost:1433;databasename=test" />
<property name="username" value="sa" />
<property name="password" value="hunter" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan">
<list>
<value>com.test.model</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.SQLServerDialect
hibernate.show_sql=true
hibernate.hbm2ddl.auto=update
</value>
</property>
</bean>
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="myTxManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:annotation-driven transaction-manager="myTxManager" />
struts.xml如下:
<struts>
<package name="struts2_hibernate_spring" extends="struts-default">
<action name="user" class="com.test.model.UserAction">
<result name="success">/success.jsp</result>
<result name="fail">/fail.jsp</result>
</action>
</package>
</struts>
……
.class类如下:
public String execute() throws Exception {
if(password.equals(password2)){
User user = new User();
user.setUsername(username);
user.setPassword(password);
hibernateTemplate.save(user);
return hibernateTemplate.find("from User").size()>0?"success":"fail";
}
return "fail";
}
不是我想写那么多,实在是没有办法了,第一次用struts2\hibernate\spring整合后出现的这个问题,我一整天了都没得解决,hibernateTemplate.save()可以,但hibernateTemplate.find()就不得了,把我的分拿去吧
??? 展开
2个回答
展开全部
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan">
<list>
<value>com.test.model</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.SQLServerDialect
hibernate.show_sql=true
hibernate.hbm2ddl.auto=update
</value>
</property>
</bean在这段配置中应该加orm 因为异常提示找不到关系映射文件
可修改成
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mappingResources">
<list>
<value>com/test/model/User.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.SQLServerDialect
hibernate.show_sql=true
hibernate.hbm2ddl.auto=update
</value>
</property>
</bean
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan">
<list>
<value>com.test.model</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.SQLServerDialect
hibernate.show_sql=true
hibernate.hbm2ddl.auto=update
</value>
</property>
</bean在这段配置中应该加orm 因为异常提示找不到关系映射文件
可修改成
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mappingResources">
<list>
<value>com/test/model/User.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.SQLServerDialect
hibernate.show_sql=true
hibernate.hbm2ddl.auto=update
</value>
</property>
</bean
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询