Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    servertype:hibernate help needed

    Hi Isomorphic,

    We were using Spring DMI till now in our project and everything was working very well.

    We are trying to introduce the smartgwt servertype:hibernate stuff to our datasources.

    We are using annotation to define our hibernate configs. So, I have not given any .cfg.xml file or mapping file

    Code:
    @Entity
    @Table(name = "STD_MATL_USE")
    @AttributeOverride(name="guid", column=@Column(name="STD_MATL_USE_SK"))
    public class StandardMaterialUse extends AbstractDomainObject {
    	/**
    	 * Generated
    	 */
    	private static final long serialVersionUID = -1484851182779890075L;
    
    	@Type(type = "org.hibernate.type.NumericBooleanType")
    	@Column(name = "STAT_IND", nullable = false)
    	private Boolean statusIndicator;
    
    	@Column(name = "STD_MATL_USE_NM", nullable = false, length = 100)
    	private String name;
    
    	@Column(name = "STD_MATL_USE_DESC", length = 500)
    	private String abbreviation;
    }
    Below is our ds.xml file

    Code:
    <DataSource ID="materialUseDatasource" serverType="hibernate" beanClassName="xxx.StandardMaterialUse" >
    I have defined hibernate config in our server.properties file
    hibernate.config.lookupStyle:spring
    hibernate.config.bean:sessionFactory

    If I use beanConfig in the ds.xml, datasource loads up and everything works fine. If I take that out from ds.xml file then I get a Null pointer exception.

    Code:
    javax.servlet.ServletException: java.lang.NullPointerException
    	at com.isomorphic.hibernate.HibernateDataSource.init(HibernateDataSource.java:191)
    	at com.isomorphic.datasource.BasicDataSource.fromConfig(BasicDataSource.java:165)
    	at com.isomorphic.datasource.DataSource.fromConfig(DataSource.java:337)
    	at com.isomorphic.datasource.FileSystemDSRepo.loadDS(FileSystemDSRepo.java:110)
    	at com.isomorphic.datasource.DataSource.forName(DataSource.java:156)
    	at com.isomorphic.datasource.DataSource.forName(DataSource.java:148)
    	at com.isomorphic.datasource.DataSource.forName(DataSource.java:143)
    	at com.isomorphic.datasource.PoolableDataSourceFactory.makeUnpooledObject(PoolableDataSourceFactory.java:95)
    	at com.isomorphic.datasource.PoolableDataSourceFactory.makeObject(PoolableDataSourceFactory.java:102)
    	at com.isomorphic.pool.PoolManager.borrowObject(PoolManager.java:82)
    	at com.isomorphic.datasource.DataSourceManager.getDataSource(DataSourceManager.java:62)
    	at com.isomorphic.servlet.DataSourceLoader.processRequest(DataSourceLoader.java:81)
    	at com.isomorphic.servlet.DataSourceLoader.doGet(DataSourceLoader.java:64)
    Am I missing something?? Can somebody help me out please??

    #2
    Could you clarify what you mean by "if you use beanConfig"? There's no such SmartGWT property.

    Comment


      #3
      Sorry, it should be configBean property of Datasource. Below configuration works fine
      Code:
      <DataSource ID="materialUseDatasource" serverType="hibernate" beanClassName="com.nike.pcs.pde.spc.domain.StandardMaterialUse" configBean="sessionFactory">

      Comment


        #4
        We can look into this - what's your exact SmartGWT version? One place to get it is the lower left-hand corner of the SmartGWT Developer Console.

        Comment


          #5
          We are using the licensed version of SmartGWT Power
          SmartClient Version: SC_SNAPSHOT-2011-03-24/PowerEdition Deployment (built 2011-03-24)

          Comment


            #6
            We're also going to need the complete server log of the request leading up to this exception (there should be logs about attempting to get a sessionFactory via Spring).

            Comment


              #7
              Have given the smart gwt log. Let me know if you need anything else
              Attached Files

              Comment


                #8
                I gave this on the url once the application booted up.
                Code:
                http://127.0.0.1:8888/xxx/sc/DataSourceLoader?dataSource=materialUseDatasource
                This threw up the exception which I gave.

                Comment


                  #9
                  It looks like a lot of the default logging has been turned off. Please revert to the log4j.isc.config.xml found in your SDK. Don't turn off logging categories when showing logs to support - we will need to re-enable the original logging every time.

                  Comment


                    #10
                    Actually, it's not completely clear if the logs are partial, another possibility is misconfigured Spring.

                    We get your sessionFactory bean and call getObject() on it. The logs suggest this is returning null, and the Spring docs indicate that this means Spring is incorrectly initialized.

                    Troubleshoot Spring and Hibernate until fetching the sessionFactory and calling getObject() works from a simple servlet (not involving SmartGWT). At that point, SmartGWT's HibernateDataSource will then also work.

                    Comment


                      #11
                      I have taken out the logs by changing the loglevel to Debug. Now the file size has increased to 714KB. Hence could not upload it here.

                      Can you please give me your email id? I will send the log file to that. Or let me know how can I make it available to you guys

                      Comment


                        #12
                        Thanks for your reply. I saw it after I posted last message.

                        I very much doubt that it has to do with Spring and Hibernate configuration. Because once I give configBean it works. I can also send you the logs generated by spring and hibernate frameworks. Again size is bigger and I need to send it in email for you.

                        Comment


                          #13
                          Sorry the code to check should be that on the target bean (sessionFactory), you can do the following:

                          Code:
                          sessionFactory.getConfiguration().getObject().getClassMapping("com.nike.pcs.pde.spc.domain.StandardMaterialUse");
                          .. and it's non-null. At that point you've got Spring & Hibernate setup correctly to be able to remove your "configBean" setting for this DataSource.

                          Comment


                            #14
                            I am able to get the mapping class. The below test passed. I could not exactly get the method you asked me to call.

                            I used org.springframework.orm.hibernate3.LocalSessionFactoryBean and I could directly get class mapping.

                            Code:
                            @Autowired
                            private LocalSessionFactoryBean sessFactory;
                            
                            
                            @Test
                            public void smartGWTTest() {
                                        Assert.assertNotNull("session factory is null", sessFactory);
                            		Object obj = sessFactory.getConfiguration().getClassMapping(
                            				"com.nike.pcs.pde.spc.domain.StandardMaterialUse");
                            		Assert.assertNotNull("Object is null", obj);
                            }

                            Comment


                              #15
                              I looked into this issue more deeply and couple of points which I wanted to highlight.

                              1. We are not using separate hibernate.cfg.xml file. We are defining our hibernate config in our application-context.xml as a bean
                              2. If I take out hibernate.config.lookupstyle from server.properties file, then even configBean thing stops working. It throws up this exception.
                              Code:
                              javax.servlet.ServletException: java.io.FileNotFoundException: C:\Work\codebase\pde\SPC\Trunk\spc\src\main\webapp\WEB-INF\classes\hibernate.cfg.xml (The system cannot find the file specified)
                              	at java.io.FileInputStream.open(Native Method)
                              	at java.io.FileInputStream.<init>(FileInputStream.java:106)
                              	at com.isomorphic.io.ISCFile.getInputStream(ISCFile.java:349)
                              	at com.isomorphic.hibernate.HibernateDataSource.initStaticConfigAndSessionFactory(HibernateDataSource.java:419)
                              	at com.isomorphic.hibernate.HibernateDataSource.initConfigAndSessionFactory(HibernateDataSource.java:332)
                              	at com.isomorphic.hibernate.HibernateDataSource.init(HibernateDataSource.java:172)
                              	at com.isomorphic.datasource.BasicDataSource.fromConfig(BasicDataSource.java:165)
                              	at com.isomorphic.datasource.DataSource.fromConfig(DataSource.java:337)
                              	at com.isomorphic.datasource.FileSystemDSRepo.loadDS(FileSystemDSRepo.java:110)
                              	at com.isomorphic.datasource.DataSource.forName(DataSource.java:156)
                              	at com.isomorphic.datasource.DataSource.forName(DataSource.java:148)
                              	at com.isomorphic.datasource.DataSource.forName(DataSource.java:143)

                              Comment

                              Working...
                              X