Announcement Announcement Module
Collapse
No announcement yet.
Not fetching data from DB using hibernat ,spring frame work Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Not fetching data from DB using hibernat ,spring frame work

    Hi I am new to spring frame work.My task is to fetch list ofcountries from the DB table countries.I am connecting DB to java class using hibernate..

    This is the way i use to connect to DB...

    {
    driverManager = new DriverManagerDataSource();
    driverManager.setDriverClassName("com.mysql.jdbc.D river");
    driverManager.setUrl("jdbc:mysql://localhost:3306/Cntr");
    driverManager.setUsername("tom");
    driverManager.setPassword("tom");

    sessionFactory = new LocalSessionFactoryBean();

    Properties props = new Properties();
    //setProperty(String key, String value)
    props.setProperty("hibernate.dialect","org.hiberna te.dialect.MySQLDialect");
    sessionFactory.setHibernateProperties(props);
    sessionFactory.setDataSource(driverManager);

    Resource[] resources = new Resource[1];
    Resource modelPathRes = new ClassPathResource("/map");

    resources[0] = modelPathRes;

    sessionFactory.setMappingDirectoryLocations(resour ces);

    hibTemplate = new HibernateTemplate();
    try {
    sessionFactory.afterPropertiesSet();
    } catch (HibernateException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }





    .Its showing the error as shown below.


    org.springframework.web.util.NestedServletExceptio n: Request processing failed; nested exception is java.lang.IllegalArgumentException: No SessionFactory specified
    java.lang.IllegalArgumentException: No SessionFactory specified
    at org.springframework.util.Assert.notNull(Assert.jav a:116)
    at org.springframework.orm.hibernate3.SessionFactoryU tils.doGetSession(SessionFactoryUtils.java:294)
    at org.springframework.orm.hibernate3.SessionFactoryU tils.getSession(SessionFactoryUtils.java:240)
    at org.springframework.orm.hibernate3.HibernateTempla te.getSession(HibernateTemplate.java:413)
    at org.springframework.orm.hibernate3.HibernateTempla te.execute(HibernateTemplate.java:355)
    at org.springframework.orm.hibernate3.HibernateTempla te.find(HibernateTemplate.java:844)
    at org.springframework.orm.hibernate3.HibernateTempla te.find(HibernateTemplate.java:836)
    at com.oceanus.tides.service.listallapartments.ListAl lApartmentsServiceImpl.listAllApartments(ListAllAp artmentsServiceImpl.java:35)
    at com.oceanus.tides.webui.listallapartments.ListAllA partmentsController.handleRequestInternal(ListAllA partmentsController.java:30)
    at org.springframework.web.servlet.mvc.AbstractContro ller.handleRequest(AbstractController.java:153)
    at org.springframework.web.servlet.mvc.SimpleControll erHandlerAdapter.handle(SimpleControllerHandlerAda pter.java:44)
    at org.springframework.web.servlet.DispatcherServlet. doDispatch(DispatcherServlet.java:723)
    at org.springframework.web.servlet.DispatcherServlet. doService(DispatcherServlet.java:663)
    at org.springframework.web.servlet.FrameworkServlet.p rocessRequest(FrameworkServlet.java:394)
    at org.springframework.web.servlet.FrameworkServlet.d oGet(FrameworkServlet.java:348)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:696)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:809)
    at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:200)
    at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:146)
    at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:209)
    at org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invokeNext(StandardPipeline.j ava:596)
    at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:433)
    at org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:948)
    at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:144)
    at org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invokeNext(StandardPipeline.j ava:596)
    at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:433)
    at org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:948)
    at org.apache.catalina.core.StandardContext.invoke(St andardContext.java:2358)
    at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:133)
    at org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invokeNext(StandardPipeline.j ava:596)
    at org.apache.catalina.valves.ErrorDispatcherValve.in voke(ErrorDispatcherValve.java:118)
    at org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invokeNext(StandardPipeline.j ava:594)
    at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:116)
    at org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invokeNext(StandardPipeline.j ava:594)
    at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:433)
    at org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:948)
    at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:127)
    at org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invokeNext(StandardPipeline.j ava:596)
    at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:433)
    at org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:948)
    at org.apache.coyote.tomcat4.CoyoteAdapter.service(Co yoteAdapter.java:152)
    at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:799)
    at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.processConnection(Http11Protocol.jav a:705)
    at org.apache.tomcat.util.net.TcpWorkerThread.runIt(P oolTcpEndpoint.java:577)
    at org.apache.tomcat.util.threads.ThreadPool$ControlR unnable.run(ThreadPool.java:683)
    at java.lang.Thread.run(Thread.java:595)


    Please help me on this...

  • #2
    See my answer in your other thread.

    Regards,
    Andreas

    Comment


    • #3
      thanx.. But still

      Hi
      Thanx for the sugestion...
      i fixed the problem..
      But now am facing another one..
      i can retrieve value but it showing the object .. not getting the value presevt in the table..

      getting error like..

      ..........INSIDE CONTROLLER.....
      ...........INSIDE ListAllApartmentsServiceImpl
      Sep 1, 2006 3:33:52 PM org.springframework.jdbc.datasource.DriverManagerD ataSource setDriverClassName
      INFO: Loaded JDBC driver: com.mysql.jdbc.Driver
      Sep 1, 2006 3:33:52 PM org.hibernate.cfg.Environment <clinit>
      INFO: Hibernate 3.1 rc3
      Sep 1, 2006 3:33:52 PM org.hibernate.cfg.Environment <clinit>
      INFO: hibernate.properties not found
      Sep 1, 2006 3:33:52 PM org.hibernate.cfg.Environment <clinit>
      INFO: using CGLIB reflection optimizer
      Sep 1, 2006 3:33:52 PM org.hibernate.cfg.Environment <clinit>
      INFO: using JDK 1.4 java.sql.Timestamp handling
      Sep 1, 2006 3:33:53 PM org.hibernate.cfg.Configuration addFile
      INFO: Reading mappings from file: /opt/jakarta-tomcat-4.1.31/webapps/tides/WEB-INF/classes/map/ListApartments.hbm.xml
      Sep 1, 2006 3:33:55 PM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
      INFO: Mapping class: com.oceanus.tides.model.listallapartments.ListApar tments -> apartments
      Sep 1, 2006 3:33:55 PM org.springframework.orm.hibernate3.LocalSessionFac toryBean afterPropertiesSet
      INFO: Building new Hibernate SessionFactory
      Sep 1, 2006 3:33:55 PM org.hibernate.cfg.Configuration secondPassCompile
      INFO: processing extends queue
      Sep 1, 2006 3:33:55 PM org.hibernate.cfg.Configuration secondPassCompile
      INFO: processing collection mappings
      Sep 1, 2006 3:33:55 PM org.hibernate.cfg.Configuration secondPassCompile
      INFO: processing association property references
      Sep 1, 2006 3:33:55 PM org.hibernate.cfg.Configuration secondPassCompile
      INFO: processing foreign key constraints
      Sep 1, 2006 3:33:56 PM org.hibernate.connection.ConnectionProviderFactory newConnectionProvider
      INFO: Initializing connection provider: org.springframework.orm.hibernate3.LocalDataSource ConnectionProvider
      Sep 1, 2006 3:33:57 PM org.hibernate.cfg.SettingsFactory buildSettings
      INFO: RDBMS: MySQL, version: 5.0.18
      Sep 1, 2006 3:33:57 PM org.hibernate.cfg.SettingsFactory buildSettings
      INFO: JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-3.0.9-stable ( $Date: 2003/10/02 15:36:12 $, $Revision: 1.27.2.25 $ )
      Sep 1, 2006 3:33:58 PM org.hibernate.dialect.Dialect <init>
      INFO: Using dialect: org.hibernate.dialect.MySQLDialect
      Sep 1, 2006 3:33:58 PM org.hibernate.transaction.TransactionFactoryFactor y buildTransactionFactory
      INFO: Using default transaction strategy (direct JDBC transactions)
      Sep 1, 2006 3:33:58 PM org.hibernate.transaction.TransactionManagerLookup Factory getTransactionManagerLookup
      INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
      Sep 1, 2006 3:33:58 PM org.hibernate.cfg.SettingsFactory buildSettings
      INFO: Automatic flush during beforeCompletion(): disabled
      Sep 1, 2006 3:33:58 PM org.hibernate.cfg.SettingsFactory buildSettings
      INFO: Automatic session close at end of transaction: disabled
      Sep 1, 2006 3:33:58 PM org.hibernate.cfg.SettingsFactory buildSettings
      INFO: JDBC batch size: 15
      Sep 1, 2006 3:33:58 PM org.hibernate.cfg.SettingsFactory buildSettings
      INFO: JDBC batch updates for versioned data: disabled
      Sep 1, 2006 3:33:58 PM org.hibernate.cfg.SettingsFactory buildSettings
      INFO: Scrollable result sets: enabled
      Sep 1, 2006 3:33:58 PM org.hibernate.cfg.SettingsFactory buildSettings
      INFO: JDBC3 getGeneratedKeys(): enabled
      Sep 1, 2006 3:33:58 PM org.hibernate.cfg.SettingsFactory buildSettings
      INFO: Connection release mode: on_close
      Sep 1, 2006 3:33:58 PM org.hibernate.cfg.SettingsFactory buildSettings
      INFO: Maximum outer join fetch depth: 2
      Sep 1, 2006 3:33:58 PM org.hibernate.cfg.SettingsFactory buildSettings
      INFO: Default batch fetch size: 1
      Sep 1, 2006 3:33:58 PM org.hibernate.cfg.SettingsFactory buildSettings
      INFO: Generate SQL with comments: disabled
      Sep 1, 2006 3:33:58 PM org.hibernate.cfg.SettingsFactory buildSettings
      INFO: Order SQL updates by primary key: disabled
      Sep 1, 2006 3:33:58 PM org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
      INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
      Sep 1, 2006 3:33:58 PM org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
      INFO: Using ASTQueryTranslatorFactory
      Sep 1, 2006 3:33:58 PM org.hibernate.cfg.SettingsFactory buildSettings
      INFO: Query language substitutions: {}
      Sep 1, 2006 3:33:58 PM org.hibernate.cfg.SettingsFactory buildSettings
      INFO: Second-level cache: enabled
      Sep 1, 2006 3:33:58 PM org.hibernate.cfg.SettingsFactory buildSettings
      INFO: Query cache: disabled
      Sep 1, 2006 3:33:58 PM org.hibernate.cfg.SettingsFactory createCacheProvider
      INFO: Cache provider: org.hibernate.cache.EhCacheProvider
      Sep 1, 2006 3:33:58 PM org.hibernate.cfg.SettingsFactory buildSettings
      INFO: Optimize cache for minimal puts: disabled
      Sep 1, 2006 3:33:58 PM org.hibernate.cfg.SettingsFactory buildSettings
      INFO: Structured second-level cache entries: disabled
      Sep 1, 2006 3:33:58 PM org.hibernate.cfg.SettingsFactory buildSettings
      INFO: Statistics: disabled
      Sep 1, 2006 3:33:58 PM org.hibernate.cfg.SettingsFactory buildSettings
      INFO: Deleted entity synthetic identifier rollback: disabled
      Sep 1, 2006 3:33:58 PM org.hibernate.cfg.SettingsFactory buildSettings
      INFO: Default entity-mode: POJO
      Sep 1, 2006 3:33:58 PM org.hibernate.impl.SessionFactoryImpl <init>
      INFO: building session factory
      Sep 1, 2006 3:33:58 PM net.sf.ehcache.config.Configurator configure
      WARNING: No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/opt/jakarta-tomcat-4.1.31/webapps/tides/WEB-INF/lib/ehcache-1.1.jar!/ehcache-failsafe.xml
      Sep 1, 2006 3:34:01 PM org.hibernate.impl.SessionFactoryObjectFactory addInstance
      INFO: Not binding factory to JNDI, no JNDI name configured
      Sep 1, 2006 3:34:01 PM org.hibernate.impl.SessionFactoryImpl checkNamedQueries
      INFO: Checking 0 named HQL queries
      Sep 1, 2006 3:34:01 PM org.hibernate.impl.SessionFactoryImpl checkNamedQueries
      INFO: Checking 0 named SQL queries
      Sep 1, 2006 3:34:01 PM org.springframework.beans.factory.xml.XmlBeanDefin itionReader loadBeanDefinitions
      INFO: Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
      Sep 1, 2006 3:34:01 PM org.springframework.jdbc.support.SQLErrorCodesFact ory <init>
      INFO: SQLErrorCodes loaded: [DB2, HSQL, MS-SQL, MySQL, Oracle, Informix, PostgreSQL, Sybase]
      .......................LiSt[com.oceanus.tides.model.listallapartments.ListApar [email protected], com.oceanus.tides.model.listallapartments.ListApar [email protected]]
      Elementscom.oceanus.tides.model.listallapartments. [email protected]
      Elementscom.oceanus.tides.model.listallapartments. [email protected]
      .........size......

      here actuall value is abc and cfg but am getting value :
      Elementscom.oceanus.tides.model.listallapartments. [email protected]
      Elementscom.oceanus.tides.model.listallapartments. [email protected]

      Help me...

      Comment


      • #4
        It seems to me your query is executing but does not yield the result you are expecting.
        So: what is the query and what do you expect?

        Regards,
        Andreas

        P.S.: Please use [c o d e] [/ c o d e] Tags to make things better readable.

        Comment


        • #5
          thanx...

          hi
          I solved the problem... any way thanks .
          Regards
          Shalid

          Comment

          Working...
          X