Announcement

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

    DataSource Hibernate integration with Naming Strategy

    Hello,
    I have problem with datasouce integration with Hibernate. I have big project with a lot of hibernate entities. So far we used EJB and DTO to retrive any objects from db. But we decied to use SmartGWT power and to integrate straight with hibernate at some views using autoDeriveSchema.
    BUT - our db is generated from model and there is set NamingStrategy. My question is : can I add NamingStrategy to hibernate config or ds.xml so that could SmartGWT handle it?
    Or do I have to re-generate model from db to my web project? O mby there is other way to do it quick and simple :)?

    #2
    There doesn't appear to be any reason that SmartGWT would need to be aware of your NamingStrategy. With the HibernateDataSource, we call Hibernate APIs and do not deal with SQL table or column names directly.

    Comment


      #3
      Thanks for replay but in my case Hibernate needs to know about my NamingStrategy. Let me explain it more specific.

      I generate db from model with my NamingStrategy
      Code:
      conf.setNamingStrategy(new ExtNamingStrategy());
      Then db is created but names are changed, for example :
      OrgUnitODB class as table is org_units (same with class members).
      So, my ds.xml is:
      Code:
      <DataSource  
          ID="OrgUnitODB"
          serverType="hibernate"
          schemaBean="mypackage.OrgUnitODB"
          autoDeriveSchema="true"
      > 
      </DataSource>
      And there is problem because smartgwt points to table OrgUnitODB instead of org_units. Same with members. When I added annotation @table(name="org_units") to my model - it worked.
      But I don't want to set all tables and variables translated names because NamingStrategy should deal with it.

      My question is. Can I somewhere specify my NamingStrategy class or such functionality is not supported by SmartGwt?

      Comment


        #4
        Hi,

        Did you specify your naming strategy in hibernate configuration?
        Check this property:
        Code:
        hibernate.ejb.naming_strategy
        Alius.

        Comment


          #5
          Thanx for reply, but it does not work. The only possibility is to add NamingStrategy programmatically if DataSources don't have such functionality.

          I am afraid I will have to generate separate model for my web project or set my sessionFactory with proper config.

          Comment


            #6
            You can supply framework with your own Hibernate config by setting following properties in your server.properties file:
            Code:
            hibernate.config.lookupStyle=factory
            hibernate.config.className=your.hibernate.config.ProviderFactory
            Class your.hibernate.config.ProviderFactory should have method create() which should return prepared (not built yet) instance of org.hibernate.cfg.Configuration (buildSessionFactory() will be executed later).

            Alius.

            Comment


              #7
              Thanks, works - you helped me a lot!

              Comment

              Working...
              X