Page 1 of 4 123 ... LastLast
Results 1 to 10 of 38

Thread: Problem in deploying Extjs-SpringMVC-Hibernate example

  1. #1
    Sencha User
    Join Date
    Nov 2011
    Posts
    149
    Answers
    2
    Vote Rating
    1
      0  

    Default Answered: Problem in deploying Extjs-SpringMVC-Hibernate example

    Hello
    I am working on a spring hibenrate extjs application and stuck at a point.
    This is my js file for creating and displaying the content in a grid.
    REFERENCE: http://loianegroner.com/2010/09/extj...agrid-example/
    I have created my own classes for hibernate and made the necessary changes and don't get any error(on execution) on the console but neither can i see the extjs grid with records.
    Stack trace
    Code:
    Mar 5, 2012 5:32:03 PM org.apache.catalina.core.AprLifecycleListener init
    INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre6\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Program Files/Java/jre6/bin/client;C:/Program Files/Java/jre6/bin;C:/Program Files/Java/jre6/lib/i386;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Microsoft SQL Server\80\Tools\Binn\;C:\Program Files\Microsoft SQL Server\90\Tools\binn\;C:\Program Files\Microsoft SQL Server\90\DTS\Binn\;C:\Program Files\Microsoft SQL Server\90\Tools\Binn\VSShell\Common7\IDE\;C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies\;C:\apache-ant-1.6.5\bin;C:\Program Files\Subversion\bin;C:\GNUstep\mingw\bin;C:\GNUstep\GNUstep\System\Tools;C:\Program Files\Java\jdk1.6.0_24
    Mar 5, 2012 5:32:04 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
    WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:StaffingApplication' did not find a matching property.
    Mar 5, 2012 5:32:04 PM org.apache.coyote.http11.Http11Protocol init
    INFO: Initializing Coyote HTTP/1.1 on http-9191
    Mar 5, 2012 5:32:04 PM org.apache.coyote.ajp.AjpProtocol init
    INFO: Initializing Coyote AJP/1.3 on ajp-8009
    Mar 5, 2012 5:32:04 PM org.apache.catalina.startup.Catalina load
    INFO: Initialization processed in 825 ms
    Mar 5, 2012 5:32:04 PM org.apache.catalina.core.StandardService startInternal
    INFO: Starting service Catalina
    Mar 5, 2012 5:32:04 PM org.apache.catalina.core.StandardEngine startInternal
    INFO: Starting Servlet Engine: Apache Tomcat/7.0.4
    Mar 5, 2012 5:32:06 PM org.apache.catalina.core.ApplicationContext log
    INFO: Initializing Spring FrameworkServlet 'StaffingApplication'
    Mar 5, 2012 5:32:06 PM org.springframework.web.servlet.FrameworkServlet initServletBean
    INFO: FrameworkServlet 'StaffingApplication': initialization started
    Mar 5, 2012 5:32:06 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
    INFO: Refreshing WebApplicationContext for namespace 'StaffingApplication-servlet': startup date [Mon Mar 05 17:32:06 IST 2012]; root of context hierarchy
    Mar 5, 2012 5:32:06 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
    INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/spring/app-config.xml]
    Mar 5, 2012 5:32:07 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
    INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/spring/db-config.xml]
    Mar 5, 2012 5:32:07 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
    INFO: Pre-instantiating singletons in org.s[email protected]12f9bcd: defining beans [candidatesController,candidatesDAO,candidatesService,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0,org.springframework.format.support.FormattingConversionServiceFactoryBean#0,org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter#0,org.springframework.web.servlet.handler.MappedInterceptor#0,viewResolver,dataSource,sessionFactory,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,transactionManager]; root of factory hierarchy
    Mar 5, 2012 5:32:07 PM org.springframework.jdbc.datasource.DriverManagerDataSource setDriverClassName
    INFO: Loaded JDBC driver: com.microsoft.sqlserver.jdbc.SQLServerDriver
    0 [main] INFO org.hibernate.cfg.annotations.Version - Hibernate Annotations 3.5.2-Final
    19 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.5.2-Final
    19 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
    29 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
    29 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
    198 [main] INFO org.hibernate.annotations.common.Version - Hibernate Commons Annotations 3.2.0.Final
    277 [main] INFO org.hibernate.cfg.AnnotationBinder - Binding entity from annotated class: com.options.model.Candidates
    337 [main] INFO org.hibernate.cfg.annotations.EntityBinder - Bind entity com.options.model.Candidates on table HC_RESUME_BANK
    436 [main] INFO org.hibernate.cfg.AnnotationBinder - Binding entity from annotated class: com.options.model.CandidateStatus
    436 [main] INFO org.hibernate.cfg.annotations.EntityBinder - Bind entity com.options.model.CandidateStatus on table HC_REQ_RESUME
    515 [main] INFO org.hibernate.cfg.AnnotationBinder - Binding entity from annotated class: com.options.model.Clients
    515 [main] INFO org.hibernate.cfg.annotations.EntityBinder - Bind entity com.options.model.Clients on table HC_CLIENTS
    515 [main] INFO org.hibernate.cfg.AnnotationBinder - Binding entity from annotated class: com.options.model.Requirements
    515 [main] INFO org.hibernate.cfg.annotations.EntityBinder - Bind entity com.options.model.Requirements on table HC_REQUISITIONS
    585 [main] INFO org.hibernate.cfg.annotations.CollectionBinder - Mapping collection: com.options.model.Requirements.candidateStatus -> HC_REQ_RESUME
    585 [main] INFO org.hibernate.cfg.annotations.CollectionBinder - Mapping collection: com.options.model.Clients.require -> HC_REQUISITIONS
    585 [main] INFO org.hibernate.cfg.annotations.CollectionBinder - Mapping collection: com.options.model.Candidates.candidateStats -> HC_REQ_RESUME
    604 [main] INFO org.hibernate.cfg.AnnotationConfiguration - Hibernate Validator not found: ignoring
    Mar 5, 2012 5:32:08 PM org.springframework.orm.hibernate3.LocalSessionFactoryBean buildSessionFactory
    INFO: Building new Hibernate SessionFactory
    624 [main] INFO org.hibernate.cfg.search.HibernateSearchEventListenerRegister - Unable to find org.hibernate.search.event.FullTextIndexEventListener on the classpath. Hibernate Search is not enabled.
    634 [main] INFO org.hibernate.connection.ConnectionProviderFactory - Initializing connection provider: org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider
    1232 [main] INFO org.hibernate.cfg.SettingsFactory - RDBMS: Microsoft SQL Server, version: 9.00.1399
    1232 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC driver: Microsoft SQL Server JDBC Driver 3.0, version: 3.0.1301.101
    1262 [main] INFO org.hibernate.dialect.Dialect - Using dialect: org.hibernate.dialect.SQLServerDialect
    1282 [main] INFO org.hibernate.transaction.TransactionFactoryFactory - Transaction strategy: org.springframework.orm.hibernate3.SpringTransactionFactory
    1292 [main] INFO org.hibernate.transaction.TransactionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
    1292 [main] INFO org.hibernate.cfg.SettingsFactory - Automatic flush during beforeCompletion(): disabled
    1292 [main] INFO org.hibernate.cfg.SettingsFactory - Automatic session close at end of transaction: disabled
    1292 [main] INFO org.hibernate.cfg.SettingsFactory - Scrollable result sets: enabled
    1292 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC3 getGeneratedKeys(): enabled
    1292 [main] INFO org.hibernate.cfg.SettingsFactory - Connection release mode: auto
    1292 [main] INFO org.hibernate.cfg.SettingsFactory - Default batch fetch size: 1
    1292 [main] INFO org.hibernate.cfg.SettingsFactory - Generate SQL with comments: disabled
    1292 [main] INFO org.hibernate.cfg.SettingsFactory - Order SQL updates by primary key: disabled
    1292 [main] INFO org.hibernate.cfg.SettingsFactory - Order SQL inserts for batching: disabled
    1292 [main] INFO org.hibernate.cfg.SettingsFactory - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
    1292 [main] INFO org.hibernate.hql.ast.ASTQueryTranslatorFactory - Using ASTQueryTranslatorFactory
    1292 [main] INFO org.hibernate.cfg.SettingsFactory - Query language substitutions: {}
    1292 [main] INFO org.hibernate.cfg.SettingsFactory - JPA-QL strict compliance: disabled
    1292 [main] INFO org.hibernate.cfg.SettingsFactory - Second-level cache: enabled
    1292 [main] INFO org.hibernate.cfg.SettingsFactory - Query cache: disabled
    1292 [main] INFO org.hibernate.cfg.SettingsFactory - Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory
    1292 [main] INFO org.hibernate.cfg.SettingsFactory - Optimize cache for minimal puts: disabled
    1292 [main] INFO org.hibernate.cfg.SettingsFactory - Structured second-level cache entries: disabled
    1302 [main] INFO org.hibernate.cfg.SettingsFactory - Echoing all SQL to stdout
    1302 [main] INFO org.hibernate.cfg.SettingsFactory - Statistics: disabled
    1302 [main] INFO org.hibernate.cfg.SettingsFactory - Deleted entity synthetic identifier rollback: disabled
    1302 [main] INFO org.hibernate.cfg.SettingsFactory - Default entity-mode: pojo
    1302 [main] INFO org.hibernate.cfg.SettingsFactory - Named query checking : enabled
    1302 [main] INFO org.hibernate.cfg.SettingsFactory - Check Nullability in Core (should be disabled when Bean Validation is on): enabled
    1362 [main] INFO org.hibernate.impl.SessionFactoryImpl - building session factory
    1642 [main] INFO org.hibernate.impl.SessionFactoryObjectFactory - Not binding factory to JNDI, no JNDI name configured
    Mar 5, 2012 5:32:09 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
    INFO: Mapped URL path [/candidates/view.action] onto handler [[email protected]]
    Mar 5, 2012 5:32:10 PM org.springframework.orm.hibernate3.HibernateTransactionManager afterPropertiesSet
    INFO: Using DataSource [[email protected]4e1] of Hibernate SessionFactory for HibernateTransactionManager
    Mar 5, 2012 5:32:10 PM org.springframework.web.servlet.FrameworkServlet initServletBean
    INFO: FrameworkServlet 'StaffingApplication': initialization completed in 3705 ms
    Mar 5, 2012 5:32:10 PM org.apache.coyote.http11.Http11Protocol start
    INFO: Starting Coyote HTTP/1.1 on http-9191
    Mar 5, 2012 5:32:10 PM org.apache.coyote.ajp.AjpProtocol start
    INFO: Starting Coyote AJP/1.3 on ajp-8009
    Mar 5, 2012 5:32:10 PM org.apache.catalina.startup.Catalina start
    INFO: Server startup in 6401 ms

    Code:
    Ext.onReady(function(){
    
        Ext.BLANK_IMAGE_URL = '/StaffingApplication/ext-3.2.1/resources/images/default/s.gif';
        
        var Contact = Ext.data.Record.create([
        {name: 'id'},
        {
            name: 'firstname',
            type: 'string'
        },{
            name: 'lastname',
            type: 'string'
        },{
            name: 'email',
            type: 'string'
        },{
            name:'statusTitle',
            type:'string'
        },{
            name:'clientName',
            type:'string'
        },{
            name:'reqTitle',
            type:'string'
        }]);
        
        var proxy = new Ext.data.HttpProxy({
            api: {
                read : 'candidates/view.action',
             
            }
        });
        
        var reader = new Ext.data.JsonReader({
            totalProperty: 'total',
            successProperty: 'success',
            idProperty: 'id',
            root: 'data',
            messageProperty: 'message'  // <-- New "messageProperty" meta-data
        }, 
        Contact);
    
     // The new DataWriter component.
        var writer = new Ext.data.JsonWriter({
            encode: true,
            writeAllFields: true
        });
        
     // Typical Store collecting the Proxy, Reader and Writer together.
        var store = new Ext.data.Store({
            id: 'user',
            proxy: proxy,
            reader: reader,
            writer: writer,  // <-- plug a DataWriter into the store just as you would a Reader
            autoSave: false // <-- false would delay executing create, update, destroy requests until specifically told to do so with some [save] buton.
        });
    
        //read the data from simple array
        store.load();
        
        Ext.data.DataProxy.addListener('exception', function(proxy, type, action, options, res) {
            Ext.Msg.show({
                title: 'ERROR',
                msg: res.message,
                icon: Ext.MessageBox.ERROR,
                buttons: Ext.Msg.OK
            });
        });
    
        
        var editor = new Ext.ux.grid.RowEditor({
            saveText: 'Update'
        });
        
    
        // create grid
        var grid = new Ext.grid.GridPanel({
            store: store,
            columns: [
                {header: "FIRSTNAME",
                 width: 170,
                 sortable: true,
                 dataIndex: 'firstname',
                 editor: {
                    xtype: 'textfield',
                    allowBlank: false
                }},
                {header: "LASTNAME",
                    width: 170,
                    sortable: true,
                    dataIndex: 'lastname',
                    editor: {
                       xtype: 'textfield',
                       allowBlank: false
                   }},
                /*{header: "PHONE #",
                 width: 160,
                 sortable: true,
                 dataIndex: 'phone',
                 editor: {
                     xtype: 'textfield',
                     allowBlank: false
                }}*/
                {header: "EMAIL",
                 width: 170,
                 sortable: true,
                 dataIndex: 'email',
                 editor: {
                    xtype: 'textfield',
                    allowBlank: false
                }},
                {header: "Status",
                    width: 170,
                    sortable: true,
                    dataIndex: 'statusTitle',
                    editor: {
                       xtype: 'textfield',
                       allowBlank: false
                   }},
                   {header: "Clientname",
                       width: 170,
                       sortable: true,
                       dataIndex: 'clientName',
                       editor: {
                          xtype: 'textfield',
                          allowBlank: false
                      }},
                      {header: "Requirement",
                          width: 170,
                          sortable: true,
                          dataIndex: 'reqTitle',
                          editor: {
                             xtype: 'textfield',
                             allowBlank: false
                         }}
            ],
            viewConfig:{forcefit:true},
            plugins: [editor],
            title: 'Candidates',
            height: 500,
            width:995,
            frame:true,
            tbar: [{
                iconCls: 'icon-user-add',
                text: 'Add Contact',
                handler: function(){
                    var e = new Contact({
                        name: 'New Guy',
                        phone: '(000) 000-0000',
                        email: '[email protected]',
                        contact_address:'Street,State'
                    });
                    editor.stopEditing();
                    store.insert(0, e);
                    grid.getView().refresh();
                    grid.getSelectionModel().selectRow(0);
                    editor.startEditing(0);
                }
            },{
                iconCls: 'icon-user-delete',
                text: 'Remove Contact',
                handler: function(){
                    editor.stopEditing();
                    var s = grid.getSelectionModel().getSelections();
                    for(var i = 0, r; r = s[i]; i++){
                        store.remove(r);
                    }
                }
            },{
                iconCls: 'icon-user-save',
                text: 'Save All Modifications',
                handler: function(){
                    store.save();
                }
            }]
        });
    
        //render to DIV
        grid.render('crud-grid');
    });
    JSP file index.jsp to render the extjs widjets.
    Code:
    <html>
    <head>
        <title>Staffing Application</title>
        
        <!-- ExtJS css -->
        <link rel="stylesheet" type="text/css" href="/StaffingApplication/ext-3.2.1/resources/css/ext-all.css" />
        
        <!-- Row Editor plugin css -->
        <link rel="stylesheet" type="text/css" href="/StaffingApplication/ext-3.2.1/examples/ux/css/rowEditorCustom.css" />
        <link rel="stylesheet" type="text/css" href="/StaffingApplication/ext-3.2.1/examples/shared/examples.css" />
        <link rel="stylesheet" type="text/css" href="/StaffingApplication/ext-3.2.1/examples/ux/css/RowEditor.css" />
    
        <!-- App custom css -->
        <link rel="stylesheet" type="text/css" href="/StaffingApplication/css/crudgrid.css" />
        
        <!-- ExtJS js -->
        <script src="/StaffingApplication/ext-3.2.1/adapter/ext/ext-base.js"></script>
        <script src="/StaffingApplication/ext-3.2.1/ext-all.js"></script>
        
        <!-- Row Editor plugin js -->
        <script src="/StaffingApplication/ext-3.2.1/examples/ux/RowEditor.js"></script>
        
        <!-- App js -->
        <script src="/StaffingApplication/js/crud-grid.js"></script>
        
    </head>
    <body></body>
    </html>
    web.xml
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
      
      <display-name>StaffingApplication</display-name>
      
      <welcome-file-list>
           <welcome-file>index.jsp</welcome-file>
      </welcome-file-list>
      
      <servlet>
            <servlet-name>StaffingApplication</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <init-param>
                <param-name>contextConfigLocation</param-name>
                <param-value>
                    /WEB-INF/spring/app-config.xml
                </param-value>
            </init-param>
            <load-on-startup>1</load-on-startup>
        </servlet>
        
        <servlet-mapping>
            <servlet-name>StaffingApplication</servlet-name>
            <url-pattern>*.action</url-pattern>
        </servlet-mapping>
        
    </web-app>
    My Controller class
    Code:
    package com.options.controller;
    
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    
    import org.apache.log4j.Logger;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.ResponseBody;
    
    
    import com.options.model.Candidates;
    import com.options.service.CandidatesService;
    
    @Controller
    public class CandidatesController {
        
        
        private CandidatesService candidatesService;
        
        @RequestMapping(value="/candidates/view.action")
        public @ResponseBody Map<String,? extends Object> view() throws Exception {
                    
            try{            
                List<Candidates> candidates = candidatesService.getCandidatesList();
                return getMap(candidates);
    
            } catch (Exception e) {
    
                return getModelMapError("Error retrieving Candidates from database.");
            }
    }
        private Map<String,Object> getMap(List<Candidates> candidates){
            
            Map<String,Object> modelMap = new HashMap<String,Object>(3);
            modelMap.put("total", candidates.size());
            modelMap.put("data", candidates);
            modelMap.put("success", true);
            return modelMap;
        }
        
        private Map<String,Object> getModelMapError(String msg){
    
            Map<String,Object> modelMap = new HashMap<String,Object>(2);
            modelMap.put("message", msg);
            modelMap.put("success", false);
    
            return modelMap;
        } 
        
        @Autowired
        public void setCandidatesService(CandidatesService candidatesService) {
            this.candidatesService = candidatesService;
        }
    
    }
    DAO class

    Code:
    import com.options.model.Candidates;
    
    @Repository
    public class CandidatesDAO implements ICandidatesDAO {
        
        private HibernateTemplate hibernateTemplate;
        @Autowired
        public void setSessionFactory(SessionFactory sessionFactory) {
            hibernateTemplate = new HibernateTemplate(sessionFactory);
        }
        
        @SuppressWarnings("unchecked")
        @Override
        public List<Candidates> getCandidates() {
            //String hql="SELECT Contact_email,contact_name,contact_phone,id,contact_details.contact_address FROM CONTACT,CONTACT_DETAILS where CONTACT.CONTACT_ID=CONTACT_DETAILS.ID";
            //return (List<Contact>) hibernateTemplate.getSessionFactory().getCurrentSession().createSQLQuery("select c.contact_id,c.contact_name,c.contact_email,c.contact_phone from contact c");
            return hibernateTemplate.find("from Candidates");
        }
    One of the Model classes
    Code:
    package com.options.model;
    
    import java.util.HashSet;
    import java.util.Set;
    
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.FetchType;
    import javax.persistence.Id;
    import javax.persistence.JoinColumn;
    import javax.persistence.OneToMany;
    import javax.persistence.OneToOne;
    import javax.persistence.PrimaryKeyJoinColumn;
    import javax.persistence.Table;
    import javax.persistence.CascadeType;
    
    import org.codehaus.jackson.annotate.JsonAutoDetect;
    
    import com.options.controller.CandidatesController;
    
    @JsonAutoDetect
    @Entity
    @Table(name="BANK_TABLE")
    public class Candidates{
    
        
        private int id;
        private String firstName;
        private String lastName;
        private String email;
        
        private Set<CandidateStatus> candidateStats = new HashSet<CandidateStatus>(0);
        
        
        @OneToMany  //(mappedBy="candidate")
        @JoinColumn(name="ResID",nullable=false,referencedColumnName="RID")
        public Set<CandidateStatus> getCandidateStats() {
                return candidateStats;
        }
        public void setCandidateStats(Set<CandidateStatus> candidateStats) {
            this.candidateStats = candidateStats;
        }
        
            
        
        @Id
        @Column(name="RID")
        public int getId() {
            return id;
        }
            
        public void setId(int id) {
            this.id = id;
        }
        
        @Column(name="FirstName")
        public String getFirstName() {
            return firstName;
        }
        public void setFirstName(String firstName) {
            this.firstName = firstName;
        }
        
        @Column(name="LastName")
        public String getLastName() {
            return lastName;
        }
        public void setLastName(String lastName) {
            this.lastName = lastName;
        }
        
        @Column(name="EmailID")
        public String getEmail() {
            return email;
        }
        public void setEmail(String email) {
            this.email = email;
        }
        
        
    }

    app-config.xml(Spring config)
    Code:
    <?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:context="http://www.springframework.org/schema/context"
        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/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
    
        <!-- Scans the classpath of this application for @Components to deploy as beans -->
        <!-- Annotated controller beans may be defined explicitly, using a standard Spring bean definition in the 
        dispatcher's context. However, the @Controller stereotype also allows for autodetection, aligned with Spring 2.5's 
        general support for detecting component classes in the classpath and auto-registering bean definitions for them. -->
        
        <context:component-scan base-package="com.options" />
        
        <!-- Configures the @Controller programming model -->
        <mvc:annotation-driven />
    
        <!-- misc -->
        <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
            <property name="suffix" value=".jsp"/>
        </bean>
        
        <!-- Configures Hibernate - Database Config -->
        <import resource="db-config.xml" />
          
    </beans>
    db-config.xml
    Code:
    <?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:tx="http://www.springframework.org/schema/tx"
        xmlns:aop="http://www.springframework.org/schema/aop"
        xsi:schemaLocation="
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
         
        <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
            <property name="driverClassName"><value>com.microsoft.sqlserver.jdbc.SQLServerDriver</value></property>
            <property name="url"><value>jdbc:sqlserver://localhost:1433;databaseName=hd</value></property>
            <property name="username"><value>root</value></property>
            <property name="password"><value>root</value></property>
        </bean>
        
        
         <!-- Hibernate SessionFactory -->
        <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
            <property name="dataSource"><ref local="dataSource"/></property>
             <property name="packagesToScan" value="com.options.model" />
             <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
                <prop key="hibernate.show_sql">true</prop>
                <!--  <prop key="hibernate.hbm2ddl.auto">create</prop>-->
            </props>
            </property>
        </bean>
        
        <!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
        <tx:annotation-driven/>
        <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
            <property name="sessionFactory"><ref local="sessionFactory"/></property>
        </bean>
        
    </beans>
    Can anybody help out with the mstake.I am a newbie trying springmvc-hibernate and used extjs with servlets previously.
    Any help would be appreciated.

    Regards
    Sach
    www.optionsconsultancy.com

  2. i think your hql have to look something like this:

    from Candidates as cands inner join fetch cands.candidateStats

    you don't have to use sql - where-joining syntax here (take a look at the hibernate-docu).

    and - exactly like this.. - if you use "from Candidates" - the hql says you want only the candidates, it ignores the setting in the domain class. If you use a loadAll(Candidates.class) - it should use the configuration at the domain class by returning all Candidates with your candidateStats.

    you may also use the criteria api... i think this works also with the domain-configuration while hql is overriding this (airc).

  3. #2
    Sencha User friend's Avatar
    Join Date
    Apr 2011
    Posts
    895
    Answers
    106
    Vote Rating
    27
      0  

    Default

    As a quick test to make sure that the serverside is actually returning JSON, call your request URL directly from the browser's address bar. This should stream the desired JSON to your browser:

    Code:
    http://localhost:8080/StaffingApplication/candidates/view.action
    If you aren't getting JSON output, then make sure that you have the Jackson Mapper libraries in WEB-INF/lib.

  4. #3
    Sencha User
    Join Date
    Nov 2011
    Posts
    149
    Answers
    2
    Vote Rating
    1
      0  

    Default

    @friend
    Thank you for the tip.It helped me to find the exact error.I have the jackson jars in the build path of the project,but i get two errors and i am not sure if it is related to jackson(json) alone.

    One is related to hibernate and other json.Adding the stacktrace below.Would be helpful if you can throw some light over it.
    I get this when i hit the URL suggested by you.

    Code:
    Hibernate: select candidates0_.RID as RID0_, candidates0_.EmailID as EmailID0_, candidates0_.FirstName as FirstName0_, candidates0_.LastName as LastName0_ from BANK_TABLE candidates0_
    19006 [http-9191-exec-3] ERROR org.hibernate.LazyInitializationException - failed to lazily initialize a collection of role: com.options.model.Candidates.candidateStats, no session or session was closed
    org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.options.model.Candidates.candidateStats, no session or session was closed
        at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:380)
        at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:372)
        at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:365)
        at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:108)
        at org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:186)
        at org.codehaus.jackson.map.ser.ContainerSerializers$CollectionSerializer.serialize(ContainerSerializers.java:128)
        at org.codehaus.jackson.map.ser.ContainerSerializers$CollectionSerializer.serialize(ContainerSerializers.java:117)
        at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:218)
        at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:122)
        at org.codehaus.jackson.map.ser.ContainerSerializers$IndexedListSerializer.serialize(ContainerSerializers.java:78)
        at org.codehaus.jackson.map.ser.ContainerSerializers$IndexedListSerializer.serialize(ContainerSerializers.java:44)
        at org.codehaus.jackson.map.ser.MapSerializer.serializeEntries(MapSerializer.java:131)
        at org.codehaus.jackson.map.ser.MapSerializer.serialize(MapSerializer.java:74)
        at org.codehaus.jackson.map.ser.MapSerializer.serialize(MapSerializer.java:19)
        at org.codehaus.jackson.map.ser.StdSerializerProvider._serializeValue(StdSerializerProvider.java:260)
        at org.codehaus.jackson.map.ser.StdSerializerProvider.serializeValue(StdSerializerProvider.java:212)
        at org.codehaus.jackson.map.ObjectMapper.writeValue(ObjectMapper.java:694)
        at org.springframework.http.converter.json.MappingJacksonHttpMessageConverter.writeInternal(MappingJacksonHttpMessageConverter.java:145)
        at org.springframework.http.converter.AbstractHttpMessageConverter.write(AbstractHttpMessageConverter.java:181)
        at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodInvoker.writeWithMessageConverters(AnnotationMethodHandlerAdapter.java:933)
        at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodInvoker.handleResponseBody(AnnotationMethodHandlerAdapter.java:898)
        at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodInvoker.getModelAndView(AnnotationMethodHandlerAdapter.java:843)
        at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:423)
        at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:409)
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
        at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:203)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:108)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:379)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:242)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:259)
        at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:281)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
    Mar 6, 2012 10:45:47 AM org.apache.catalina.core.StandardWrapperValve invoke
    SEVERE: Servlet.service() for servlet [StaffingApplication] in context with path [/StaffingApplication] threw exception
    org.codehaus.jackson.map.JsonMappingException: failed to lazily initialize a collection of role: com.options.model.Candidates.candidateStats, no session or session was closed (through reference chain: java.util.HashMap["data"]->java.util.ArrayList[0]->com.options.model.Candidates["candidateStats"])
        at org.codehaus.jackson.map.JsonMappingException.wrapWithPath(JsonMappingException.java:214)
        at org.codehaus.jackson.map.JsonMappingException.wrapWithPath(JsonMappingException.java:179)
        at org.codehaus.jackson.map.ser.SerializerBase.wrapAndThrow(SerializerBase.java:80)
        at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:127)
        at org.codehaus.jackson.map.ser.ContainerSerializers$IndexedListSerializer.serialize(ContainerSerializers.java:78)
        at org.codehaus.jackson.map.ser.ContainerSerializers$IndexedListSerializer.serialize(ContainerSerializers.java:44)
        at org.codehaus.jackson.map.ser.MapSerializer.serializeEntries(MapSerializer.java:131)
        at org.codehaus.jackson.map.ser.MapSerializer.serialize(MapSerializer.java:74)
        at org.codehaus.jackson.map.ser.MapSerializer.serialize(MapSerializer.java:19)
        at org.codehaus.jackson.map.ser.StdSerializerProvider._serializeValue(StdSerializerProvider.java:260)
        at org.codehaus.jackson.map.ser.StdSerializerProvider.serializeValue(StdSerializerProvider.java:212)
        at org.codehaus.jackson.map.ObjectMapper.writeValue(ObjectMapper.java:694)
        at org.springframework.http.converter.json.MappingJacksonHttpMessageConverter.writeInternal(MappingJacksonHttpMessageConverter.java:145)
        at org.springframework.http.converter.AbstractHttpMessageConverter.write(AbstractHttpMessageConverter.java:181)
        at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodInvoker.writeWithMessageConverters(AnnotationMethodHandlerAdapter.java:933)
        at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodInvoker.handleResponseBody(AnnotationMethodHandlerAdapter.java:898)
        at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodInvoker.getModelAndView(AnnotationMethodHandlerAdapter.java:843)
        at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:423)
        at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:409)
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
        at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:203)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:108)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:379)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:242)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:259)
        at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:281)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
    Caused by: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.options.model.Candidates.candidateStats, no session or session was closed
        at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:380)
        at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:372)
        at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:365)
        at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:108)
        at org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:186)
        at org.codehaus.jackson.map.ser.ContainerSerializers$CollectionSerializer.serialize(ContainerSerializers.java:128)
        at org.codehaus.jackson.map.ser.ContainerSerializers$CollectionSerializer.serialize(ContainerSerializers.java:117)
        at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:218)
        at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:122)
        ... 35 more
    Any changes to the DAO needed as the session error is beng thrown.?I have added the dao in the frst post for reference.

    Thanks and Regards
    sach
    www.optionsconsultancy.com

  5. #4
    Sencha User
    Join Date
    Nov 2011
    Posts
    149
    Answers
    2
    Vote Rating
    1
      0  

    Default

    Also,friend
    I am having multiple tables in the application(4 to be precise.)
    And I am quite sure this must be causing error.I want the data from all 4 tables joined together using Hibernate annotations.
    Please,suggest some steps,tutorials to move forward.

    Thanks
    Sach
    www.optionsconsultancy.com

  6. #5
    Sencha User friend's Avatar
    Join Date
    Apr 2011
    Posts
    895
    Answers
    106
    Vote Rating
    27
      0  

    Default

    LazyInit is a common Hibernate issue where mapped child collections are lazy-loaded by default. You'll get better help with this issue by searching/posting in the Hibenate and/or Spring Forums.

    As a helpful hint, try the search terms OpenSessionInViewInterceptor or OpenSessionInViewFilter.

  7. #6
    Sencha User
    Join Date
    Nov 2011
    Posts
    149
    Answers
    2
    Vote Rating
    1
      0  

    Default

    Hey thanks friend,
    I was able to get around the lazy load issue using Hibernate.initialize();
    But jackson seams to be troubling me still.
    Here's the stacktrace that i get now.
    Though I get the json file on hitting the url its not appropriate.

    I think i am close and would like to know what i may be doing wrong.

    Code:
    at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:122)
        at org.codehaus.jackson.map.ser.ContainerSerializers$CollectionSerializer.serialize(ContainerSerializers.java:151)
        at org.codehaus.jackson.map.ser.ContainerSerializers$CollectionSerializer.serialize(ContainerSerializers.java:117)
        at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:218)
        at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:122)
        at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:218)
        at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:122)
        at org.codehaus.jackson.map.ser.ContainerSerializers$CollectionSerializer.serialize(ContainerSerializers.java:151)
        at org.codehaus.jackson.map.ser.ContainerSerializers$CollectionSerializer.serialize(ContainerSerializers.java:117)
        at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:218)
        at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:122)
        at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:218)
        at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:122)
        at org.codehaus.jackson.map.ser.ContainerSerializers$CollectionSerializer.serialize(ContainerSerializers.java:151)
        at org.codehaus.jackson.map.ser.ContainerSerializers$CollectionSerializer.serialize(ContainerSerializers.java:117)
        at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:218)
        at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:122)
        at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:218)
        at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:122)
        at org.codehaus.jackson.map.ser.ContainerSerializers$CollectionSerializer.serialize(ContainerSerializers.java:151)
        at org.codehaus.jackson.map.ser.ContainerSerializers$CollectionSerializer.serialize(ContainerSerializers.java:117)
        at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:218)
        at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:122)
        at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:218)
        at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:122)
        at org.codehaus.jackson.map.ser.ContainerSerializers$CollectionSerializer.serialize(ContainerSerializers.java:151)
        at org.codehaus.jackson.map.ser.ContainerSerializers$CollectionSerializer.serialize(ContainerSerializers.java:117)

  8. #7
    Sencha User
    Join Date
    Feb 2010
    Posts
    125
    Answers
    7
    Vote Rating
    3
      0  

    Default

    that's not the complete stacktrace, isn't it? What's the correct exception name and so on? For Jackson there is a hibernate module (just google it - there is maven dep as well), which you can configure in your object mapper ... i have extended object mapper and configure that with registerModule in the constructor.

    That works very fine for me... but you have to make sure that all objects you want to present or serialize into json are initialized in your controller. In Fact you have to iterate through your collections (persistant-bags). I don't think it will be enough to just call initialize on the collection (the items itself are lazy).

    All those attributes you don't need at the client (not initialized) are considered as null values by the hibernate-module of jackson and therefor not serialized into json.

  9. #8
    Sencha User friend's Avatar
    Join Date
    Apr 2011
    Posts
    895
    Answers
    106
    Vote Rating
    27
      0  

    Default

    The Spring Framework already has a Jackson-based View Resolver built-in, so you'll want to avoid the Hibernate module lest you run into conflicts.

    Instead of Hibernate.initialize(), consider using the various @Fetch annotations in your Model classes to specify how child collections should be handled.

  10. #9
    Sencha User
    Join Date
    Feb 2010
    Posts
    125
    Answers
    7
    Vote Rating
    3
      0  

    Default

    erm... no. The spring framework has a jackson view resolver, which acutally uses a instance of a object mapper. Which object mapper one use you can configure in your spring configuration and of course you can also configure the hibernate-module as part of jackson - this won't get you into conflict with spring. I actually have that configuration running with spring. I also did some changes on the bean-deserializer of jackson because of the json structure extjs wants - no problems with spring here...

    Reconfiguring your jpa/hibernate beans to always catch eagerly isn't the right solution... or at least should not be

  11. #10
    Sencha User
    Join Date
    Nov 2011
    Posts
    149
    Answers
    2
    Vote Rating
    1
      0  

    Default

    Thank you born and friend for sharing your views and guiding me.
    I am still stuck and hence adding my model classes.I tried using the @Fetch(FetchMode.JOIN) as suggested by friend but still not getting it to work.

    Other way round I tried(break down the problem) to fetch only a SINGLE class with annotations and worked easily giving me the required JSON.

    Now I am back to using joins (probably unaware of the best way to do it) and again facing the same issue.

    Here adding my models for reference and the DAO.

    CandidateStatus.java
    Code:
    @Entity
    @Table(name="HC_REQ_RESUME")
    
    public class CandidateStatus{
        
        private int id;
        private String statusTitle;
        private Candidates candidate;
        private int reqid;
      
        public int getReqid() {
            return reqid;
        }
    
        public void setReqid(int reqid) {
            this.reqid = reqid;
        }
    
        @ManyToOne //(fetch = FetchType.LAZY,cascade=CascadeType.ALL,targetEntity=Candidates.class)
        @Fetch(FetchMode.JOIN)
        @JoinColumn(name="ResID",insertable=false,updatable=false)
        @ForeignKey(name = "FK_ResID")
        public Candidates getCandidate() {
            return candidate;
        }
        
        public void setCandidate(Candidates candidate) {
            this.candidate = candidate;
        }
        
        @Id
        @Column(name="RID",insertable=false,updatable=false)
        public int getId() {
            return id;
        }
        public void setId(int id) {
            this.id = id;
        }
        
        @Column(name="StatusTitle")
        
        public String getStatusTitle() {
            return statusTitle;
        }
        public void setStatusTitle(String statusTitle) {
            this.statusTitle = statusTitle;
        }
        
    }

    Candidate.java
    Code:
    @JsonAutoDetect
    @Entity
    @Table(name="HC_RESUME_BANK")
    public class Candidates{
    
        private int id;
        private String firstName;
        private String lastName;
        private String email;
        
        private Set<CandidateStatus> candidateStats = new HashSet<CandidateStatus>(0);
        
        @OneToMany  //(mappedBy="candidate")
        @Fetch(FetchMode.JOIN)
        @JoinColumn(name="ResID",nullable=false,referencedColumnName="RID")
        
        public Set<CandidateStatus> getCandidateStats() {
                return candidateStats;
        }
        public void setCandidateStats(Set<CandidateStatus> candidateStats) {
            this.candidateStats = candidateStats;
        }
            
        @Id
        @Column(name="RID")
        public int getId() {
            return id;
        }
            
        public void setId(int id) {
            this.id = id;
        }
        
        @Column(name="FirstName")
        public String getFirstName() {
            return firstName;
        }
        public void setFirstName(String firstName) {
            this.firstName = firstName;
        }
        
        @Column(name="LastName")
        public String getLastName() {
            return lastName;
        }
        public void setLastName(String lastName) {
            this.lastName = lastName;
        }
        
        @Column(name="EmailID")
        public String getEmail() {
            return email;
        }
        public void setEmail(String email) {
            this.email = email;
        }
        
    }
    DAO
    Code:
    @Repository
    public class CandidatesDAO implements ICandidatesDAO {
        
        private HibernateTemplate hibernateTemplate;
        @Autowired
        public void setSessionFactory(SessionFactory sessionFactory) {
            hibernateTemplate = new HibernateTemplate(sessionFactory);
            
        }
        
        @SuppressWarnings("unchecked")
        @Override
        public List<Candidates> getCandidates() {
            
            return hibernateTemplate.find("from Candidates"); //This should return values of both tables using join
        }
    Can you suggest what should be the exact way of acheving it?Do i have to write a explicit join query?
    I am not able to find any examples based on it,so any details would be helpful.

    I am using an existing database so i have to use the keys that exist in the database and cannot build a join table.
    I have my spring config file configured(Posted earlier).I am using spring3.1 hibernate 4 and extjs3.2.1

    Regards
    Sach

Page 1 of 4 123 ... LastLast

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •