java - The method getCurrentSession() is undefined for the type SessionFactory -
java - The method getCurrentSession() is undefined for the type SessionFactory -
i'm doing web based project using maven,spring , hibernate.i have faced problem. problem whenever i'm using sessionfactory.getcurrentsession() showing error , error is
the method getcurrentsession() undefined type sessionfactory
here pom.xml
<project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelversion>4.0.0</modelversion> <groupid>org.mahin.webchatapp</groupid> <artifactid>webchatapp</artifactid> <version>1.0-snapshot</version> <packaging>war</packaging> <name>webchatapp</name> <description>for chatting</description> <properties> <spring.version>4.1.1.release</spring.version> <hibernate.version>4.3.6.final</hibernate.version> </properties> <dependencies> <!-- spring --> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-context</artifactid> <version>${spring.version}</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-webmvc</artifactid> <version>${spring.version}</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-orm</artifactid> <version>${spring.version}</version> </dependency> <!-- hibernate --> <dependency> <groupid>org.hibernate</groupid> <artifactid>hibernate-core</artifactid> <version>${hibernate.version}</version> </dependency> <!-- java ee --> <dependency> <groupid>javax.servlet</groupid> <artifactid>javax.servlet-api</artifactid> <version>3.0.1</version> <scope>provided</scope> </dependency> <dependency> <groupid>jstl</groupid> <artifactid>jstl</artifactid> <version>1.2</version> </dependency> <!-- others --> <dependency> <groupid>commons-dbcp</groupid> <artifactid>commons-dbcp</artifactid> <version>1.4</version> </dependency> <dependency> <groupid>mysql</groupid> <artifactid>mysql-connector-java</artifactid> <version>5.1.32</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-compiler-plugin</artifactid> <version>3.1</version> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> </plugins> </build> </project>
here servlet-context.xml
<?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:mvc="http://www.springframework.org/schema/mvc" xmlns:beans="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemalocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd"> <!-- enable @controller annotation back upwards --> <mvc:annotation-driven /> <!-- map simple view name such "test" /web-inf/test.jsp --> <bean class="org.springframework.web.servlet.view.internalresourceviewresolver"> <property name="prefix" value="/web-inf/" /> <property name="suffix" value=".jsp" /> </bean> <!-- scan classpath annotations (eg: @service, @repository etc) --> <context:component-scan base-package="com.mahin"/> <!-- jdbc info source. assumed have mysql running on localhost port 3306 username root , blank password. alter below if it's not case --> <bean id="mydatasource" class="org.apache.commons.dbcp.basicdatasource" destroy-method="close"> <property name="driverclassname" value="com.mysql.jdbc.driver"/> <property name="url" value="jdbc:mysql://localhost:3306/webchatapp"/> <property name="username" value="root"/> <property name="password" value=""/> <property name="validationquery" value="select 1"/> </bean> <!-- hibernate session mill --> <bean id="mysessionfactory" class="org.springframework.orm.hibernate4.localsessionfactorybean"> <property name="datasource" ref="mydatasource"/> <property name="packagestoscan"> <array> <value>com.mahin.models</value> </array> </property> <property name="hibernateproperties"> <value> hibernate.dialect=org.hibernate.dialect.mysqldialect </value> </property> </bean> <!-- hibernate transaction manager --> <bean id="transactionmanager" class="org.springframework.orm.hibernate4.hibernatetransactionmanager"> <property name="sessionfactory" ref="mysessionfactory"/> </bean> <!-- activates annotation based transaction management --> <tx:annotation-driven transaction-manager="transactionmanager"/> </beans>
here dao class problem:
package com.mahin.daos; import java.util.list; import org.apache.cxf.service.invoker.sessionfactory; import org.hibernate.session; import org.springframework.beans.factory.annotation.autowired; import org.springframework.stereotype.repository; import com.mahin.models.users; @repository public class usersdao implements webchatdaos{ @autowired private sessionfactory sessionfactory; private session getcurrentsession() { homecoming sessionfactory.getcurrentsession(); } @override public void adduser(users user) { getcurrentsession().save(user); } @override public void updateuser(users user) { // todo auto-generated method stub } @override public users getuser(int id) { // todo auto-generated method stub homecoming null; } @override public void deleteuser(int id) { // todo auto-generated method stub } @override public list<users> getusers() { // todo auto-generated method stub homecoming null; } }
can tell problem?
looks import wrong sessionfactory
. use:
import org.hibernate.sessionfactory;
instead of:
import org.apache.cxf.service.invoker.sessionfactory;
java hibernate
Comments
Post a Comment