Announcement

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

    Using Hibernate Annotations with SmartGWT

    Hi everyone,

    I'm evaluating SmartGWTEE these days and I have a question:

    I'd like to use Hibernate Annotations instead of mapped files but the java server tries to instantiate a hibernate Config object instead of an AnnotationConfiguration object required for annotations.

    I got it working by creating a custom data source, like in the ORM DataSource example and changing hibernateConfig to use AnnotationConfiguration instead of org.​hibernate.​cfg.Configuration.

    However, I'd like to use annotations without a custom data source to take benefit of the full SmartGWTEE/Hibernate features.

    Is it possible to configure/override the Configuration Object?

    #2
    Ok, after reading some more through the docs I understand that if I want to use the built in hibernate connector (serverType="hibernate") I don't need any mapping or annotations.

    So, I created the following ds file (DeptDataSource.ds.xml):

    Code:
    <DataSource
        ID="DeptDataSource"
        serverType="hibernate"
        tableName="dept"
    >
        <fields>
            <field name="deptId" type="identity" primaryKey="true" canEdit="false" />
            <field name="deptCode" type="text" />
            <field name="deptDesc" type="date" />  
        </fields>
    
    </DataSource>
    the hibernate cfg file has only the connection details:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
    <hibernate-configuration>
      <session-factory>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/mailer</property>
        <property name="hibernate.connection.username">mailer</property>
        <property name="hibernate.connection.password">kfnj4972h7</property>
       </session-factory>
    </hibernate-configuration>
    When I try to run the project I get the following exception:

    Code:
    INFO: === 2010-02-12 12:28:20,041 [-(2)] DEBUG RPCManager - Request #1 (DSRequest) payload: {
        criteria:{},
        operationConfig:{dataSource:"DeptDataSource", operationType:"fetch", textMatchStyle:"substring"},
        startRow:0,
        endRow:75,
        componentId:"isc_OID_4",
        appID:"builtinApplication",
        operation:"DeptDataSource_fetch",
        oldValues:{}
    }
    
    INFO: DS name: DeptDataSource
    INFO: === 2010-02-12 12:28:21,072 [-(2)] DEBUG AppBase - [builtinApplication.DeptDataSource_fetch] No userTypes defined, allowing anyone access to all operations for this application
    
    INFO: === 2010-02-12 12:28:21,072 [-(2)] DEBUG AppBase - [builtinApplication.DeptDataSource_fetch] No public zero-argument method named '_DeptDataSource_fetch' found, performing generic datasource operation
    
    INFO: === 2010-02-12 12:28:21,072 [-(2)] INFO  HibernateDataSource - [builtinApplication.DeptDataSource_fetch] Performing fetch operation with
            criteria: {}        values: {}
    
    INFO: === 2010-02-12 12:28:21,087 [-(2)] WARN  RequestContext - dsRequest.execute() failed: 
    java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer
            at com.isomorphic.hibernate.HibernateDataSource.buildCriteria(HibernateDataSource.java:823)
            at com.isomorphic.hibernate.HibernateDataSource.execute(HibernateDataSource.java:515)
            at com.isomorphic.application.AppBase.executeDefaultDSOperation(AppBase.java:728)
            at com.isomorphic.application.AppBase.executeAppOperation(AppBase.java:665)
    Is there a bug in HibernateDataSource.java or there's something wrong with my configuration?

    I got the same exception when I tried the CustomDataSource example but I changed the criteria.uniqueResult() cast to long and it worked.

    Any thoughts on the issue? Thank you!
    Last edited by bftanase; 12 Feb 2010, 11:03.

    Comment


      #3
      Smart GWT defaults to using Long to represent whole number values, and Hibernate is not smart enough to just convert this to int. It's something we plan to workaround, however, if you want a connection to a SQL DB without the need to create a Java bean, the serverType="sql" option is more powerful, less finicky and requires less configuration.

      Comment


        #4
        Thanks for the info.

        One more question: if I want to use operation binding in the data source xml, like this:

        Code:
          <operationBindings>
            <operationBinding operationType="fetch" customValueFields="deptDesc" customCriteriaFields="deptDesc">
              <tableClause>email, dept</tableClause>
              <whereClause>email.deptId = dept.deptId AND ($defaultWhereClause)</whereClause>
            </operationBinding>
          </operationBindings>
        Do I need the Power version, or is it available in Pro?

        Comment


          #5
          That's the "SQL Templating" feature, and comes with Power or better licenses.

          Comment

          Working...
          X