Announcement

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

    How to use Hibernate UUID with smartgwt

    Hello,

    I currently evaluating the smartgwt enterprise edition (3.1d) and tried to save an Hibernate Entity which has an ID declared as followed:

    Code:
    	@Id
    	@GeneratedValue(generator = "uuid")
    	@GenericGenerator(name = "uuid", strategy = "uuid2")
    	@Column(updatable = false, length = 36)
    	private String uuid;
    If I use the fielddefinition:
    Code:
    <field name="uuid" type="sequence" hidden="true" primaryKey="true" />
    I get the following Error:
    Code:
    INFO  Validation - [builtinApplication.evoProductAttribute_update] Validation error: [
        {
            uuid:{
                errorMessage:"Must be a whole number."
            }
        }
    ]
    But if I set the field type to text:
    Code:
    <field name="uuid" type="text" hidden="true" primaryKey="true" />
    I get the Following Error:
    Code:
    com.isomorphic.base.UpdateWithoutPKException: Criteria received from the client for add operation is missing the following non-sequence primary key fields: [uuid]. Either provide all primary key fields that are not sequences, or set allowMultiUpdate on the OperationBinding
    Can you tell me how to solve this problem?

    #2
    You need post the complete server-side log for the request, and your DataSource, and your exact version. Please never omit this information.

    Comment


      #3
      The version is: SNAPSHOT_v9.0d_2012-09-17/EVAL Deployment 2012-09-17

      These are my classes:

      Code:
      @Entity
      @Table(name = "attribute")
      public class Attribute {
      
      	@Id
      	@GeneratedValue(generator = "uuid")
      	@GenericGenerator(name = "uuid", strategy = "uuid2")
      	@Column(updatable = false, length = 36)
      	private Long id;
      	private String value;
      	@ManyToOne
      	private AttributeDefinition definition;
      
      /* ... getter and setter ... */
      Code:
      @Entity
      @Table(name="attribute_definition")
      public class AttributeDefinition{
      
      	@Id
      	private  String name;
      	private  String type;
      
      /* ... getter and setter ... */
      and the DatasourceDefinitions:

      Code:
      <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
      <DataSource ID="attribute"
                  serverType="hibernate"
                  dropExtraFields="true"
                  beanClassName="test.Attribute">
          <fields>
              <field name="id" type="text" primaryKey="true" />
              <field name="value" type="text"/>
              <field name="definition" required="true" canEdit="true" foreignKey="attributeDefinition.name"/>
          </fields>
      </DataSource>
      Code:
      <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
      <DataSource
              ID="attributeDefinition"
              serverType="hibernate"
              dropExtraFields="true"
              beanClassName="test.AttributeDefinition"
              >
          <fields>
              <field name="name" type="text" primaryKey="true"/>
              <field name="type" type="text" />
          </fields>
      </DataSource>
      And the EntryPoint (copied and modified from http://www.smartclient.com/smartgwte...ase/#form_copy).

      Code:
      public class Entry implements EntryPoint {
      
      	public void onModuleLoad() {
      
      		final ListGrid attributeDefinition = new ListGrid();
      		attributeDefinition.setDataSource(DataSource.get("attributeDefinition"));
      		attributeDefinition.setCanDragRecordsOut(true);
      		attributeDefinition.setDragDataAction(DragDataAction.COPY);
      		attributeDefinition.setAlternateRecordStyles(true);
      		attributeDefinition.setAutoFetchData(true);
      		attributeDefinition.setFields( new ListGridField("name"), new ListGridField("type"));
      
      		final ListGrid attribute = new ListGrid();
      		attribute.setDataSource(DataSource.get("attribute"));
      		attribute.setCanAcceptDroppedRecords(true);
      		attribute.setCanRemoveRecords(true);
      		attribute.setAlternateRecordStyles(true);
      		attribute.setAutoFetchData(true);
      		attribute.setAutoFetchTextMatchStyle(TextMatchStyle.EXACT);
      		ListGridField type = new ListGridField("type");
      		type.setIncludeFrom("attributeDefinition.type");
      		attribute.setFields( new ListGridField("id"), new ListGridField("value"),  new ListGridField("definition"), type);
      
      		HLayout mainLayout = new HLayout();
      		mainLayout.setWidth100();
      		mainLayout.setHeight100();
      		mainLayout.addMember(attributeDefinition);
      		mainLayout.addMember(attribute);
      
      		mainLayout.draw();
      
      	}
      And this is the Error I got:

      Code:
      === 2012-09-20 01:25:44,425 [80-2] INFO  RequestContext - URL: '/test/sc/IDACall', User-Agent: 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2) Gecko/20100101 Firefox/10.0.2': Moz (Gecko) with Accept-Encoding header
      === 2012-09-20 01:25:44,425 [80-2] DEBUG IDACall - Header Name:Value pair: host:127.0.0.1:8080
      === 2012-09-20 01:25:44,425 [80-2] DEBUG IDACall - Header Name:Value pair: user-agent:Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2) Gecko/20100101 Firefox/10.0.2
      === 2012-09-20 01:25:44,425 [80-2] DEBUG IDACall - Header Name:Value pair: accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
      === 2012-09-20 01:25:44,430 [80-2] DEBUG IDACall - Header Name:Value pair: accept-language:de,de-de;q=0.7,en;q=0.3
      === 2012-09-20 01:25:44,430 [80-2] DEBUG IDACall - Header Name:Value pair: accept-encoding:gzip, deflate
      === 2012-09-20 01:25:44,430 [80-2] DEBUG IDACall - Header Name:Value pair: connection:keep-alive
      === 2012-09-20 01:25:44,430 [80-2] DEBUG IDACall - Header Name:Value pair: content-type:application/x-www-form-urlencoded; charset=UTF-8
      === 2012-09-20 01:25:44,430 [80-2] DEBUG IDACall - Header Name:Value pair: referer:http://127.0.0.1:8080/index.html?gwt.codesvr=127.0.0.1:9997
      === 2012-09-20 01:25:44,432 [80-2] DEBUG IDACall - Header Name:Value pair: content-length:1011
      === 2012-09-20 01:25:44,432 [80-2] DEBUG IDACall - Header Name:Value pair: cookie:GLog=%7B%0D%20%20%20%20left%3A960%2C%20%0D%20%20%20%20top%3A0%2C%20%0D%20%20%20%20width%3A942%2C%20%0D%20%20%20%20height%3A921%2C%20%0D%20%20%20%20priorityDefaults%3A%7B%0D%20%20%20%20%20%20%20%20Log%3A4%0D%20%20%20%20%7D%2C%20%0D%20%20%20%20defaultPriority%3A4%2C%20%0D%20%20%20%20trackRPC%3Atrue%0D%7D; isc_cState=ready; JSESSIONID=17DD9EE8C70B93FF7E46B5B0ADDA6267
      === 2012-09-20 01:25:44,434 [80-2] DEBUG IDACall - Header Name:Value pair: pragma:no-cache
      === 2012-09-20 01:25:44,434 [80-2] DEBUG IDACall - Header Name:Value pair: cache-control:no-cache
      === 2012-09-20 01:25:44,434 [80-2] DEBUG IDACall - session exists: 17DD9EE8C70B93FF7E46B5B0ADDA6267
      === 2012-09-20 01:25:44,434 [80-2] DEBUG IDACall - remote user: null
      === 2012-09-20 01:25:44,437 [80-2] DEBUG XML - Parsed XML from (in memory stream): 2ms
      === 2012-09-20 01:25:44,440 [80-2] DEBUG RPCManager - Processing 1 requests.
      === 2012-09-20 01:25:44,442 [80-2] DEBUG RPCManager - Request #1 (DSRequest) payload: {
          values:{
              name:"foo",
              type:"text",
              definition:"foo"
          },
          operationConfig:{
              dataSource:"attribute",
              operationType:"add"
          },
          componentId:"isc_ListGrid_1",
          appID:"builtinApplication",
          operation:"attribute_add",
          oldValues:{
              name:"foo",
              type:"text",
              definition:"foo"
          },
          criteria:{
          }
      }
      === 2012-09-20 01:25:44,446 [80-2] INFO  IDACall - Performing 1 operation(s)
      === 2012-09-20 01:25:44,446 [80-2] DEBUG DeclarativeSecurity - Processing security checks for DataSource null, field null
      === 2012-09-20 01:25:44,446 [80-2] DEBUG DeclarativeSecurity - DataSource attribute is not in the pre-checked list, processing...
      === 2012-09-20 01:25:44,446 [80-2] DEBUG AppBase - [builtinApplication.attribute_add] No userTypes defined, allowing anyone access to all operations for this application
      === 2012-09-20 01:25:44,446 [80-2] DEBUG AppBase - [builtinApplication.attribute_add] No public zero-argument method named '_attribute_add' found, performing generic datasource operation
      === 2012-09-20 01:25:44,448 [80-2] INFO  HibernateDataSource - [builtinApplication.attribute_add] Performing add operation with
      	criteria: {name:"foo",type:"text",definition:"foo"}	values: {name:"foo",type:"text",definition:"foo"}
      === 2012-09-20 01:25:44,449 [80-2] WARN  RequestContext - dsRequest.execute() failed: 
      com.isomorphic.base.UpdateWithoutPKException: Criteria received from the client for add operation is missing the following non-sequence primary key fields: [id]. Either provide all primary key fields that are not sequences, or set allowMultiUpdate on the OperationBinding
      	at com.isomorphic.hibernate.HibernateDataSource.processRequest(HibernateDataSource.java:804)
      	at com.isomorphic.hibernate.HibernateDataSource.executeAdd(HibernateDataSource.java:724)
      	at com.isomorphic.datasource.DataSource.execute(DataSource.java:1359)
      	at com.isomorphic.application.AppBase.executeDefaultDSOperation(AppBase.java:726)
      	at com.isomorphic.application.AppBase.executeAppOperation(AppBase.java:658)
      	at com.isomorphic.application.AppBase.execute(AppBase.java:491)
      	at com.isomorphic.datasource.DSRequest.execute(DSRequest.java:2000)
      	at com.isomorphic.servlet.IDACall.handleDSRequest(IDACall.java:216)
      	at com.isomorphic.servlet.IDACall.processRPCTransaction(IDACall.java:173)
      	at com.isomorphic.servlet.IDACall.processRequest(IDACall.java:138)
      	at com.isomorphic.servlet.IDACall.doPost(IDACall.java:74)
      	at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
      	at com.isomorphic.servlet.BaseServlet.service(BaseServlet.java:152)
      	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      	at com.isomorphic.servlet.CompressionFilter.doFilter(CompressionFilter.java:259)
      	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
      	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
      	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
      	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
      	at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:861)
      	at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)
      	at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1584)
      	at java.lang.Thread.run(Thread.java:662)
      === 2012-09-20 01:25:44,450 [80-2] DEBUG RPCManager - Content type for RPC transaction: text/plain; charset=UTF-8
      === 2012-09-20 01:25:44,452 [80-2] DEBUG RPCManager - non-DMI response, dropExtraFields: true
      === 2012-09-20 01:25:44,453 [80-2] INFO  Compression - /test/sc/IDACall: 346 -> 247 bytes

      Comment


        #4
        As long as you declare your data source field like this:
        Code:
        <field name="id" type="text" primaryKey="true" />
        it is OK to get UpdateWithoutPKException, cause field is *not* of type "sequence" and data source expects field value for add operation.

        You should fall back to declaring field type as "sequence". Could you please do that and provide detailed information on what's wrong with it?

        Comment


          #5
          ps. I tried to reproduce your issue with information from your original post, but failed to get validation error you were getting.

          Comment


            #6
            If I set the type to sequence, adding a new record is not the problem. But when updating the record i get the following error:

            Code:
            === 2012-09-20 12:16:21,279 [80-6] INFO  RequestContext - URL: '/test/sc/IDACall', User-Agent: 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2) Gecko/20100101 Firefox/10.0.2': Moz (Gecko) with Accept-Encoding header
            === 2012-09-20 12:16:21,280 [80-6] DEBUG IDACall - Header Name:Value pair: host:127.0.0.1:8080
            === 2012-09-20 12:16:21,280 [80-6] DEBUG IDACall - Header Name:Value pair: user-agent:Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2) Gecko/20100101 Firefox/10.0.2
            === 2012-09-20 12:16:21,280 [80-6] DEBUG IDACall - Header Name:Value pair: accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
            === 2012-09-20 12:16:21,284 [80-6] DEBUG IDACall - Header Name:Value pair: accept-language:de,de-de;q=0.7,en;q=0.3
            === 2012-09-20 12:16:21,284 [80-6] DEBUG IDACall - Header Name:Value pair: accept-encoding:gzip, deflate
            === 2012-09-20 12:16:21,284 [80-6] DEBUG IDACall - Header Name:Value pair: connection:keep-alive
            === 2012-09-20 12:16:21,284 [80-6] DEBUG IDACall - Header Name:Value pair: content-type:application/x-www-form-urlencoded; charset=UTF-8
            === 2012-09-20 12:16:21,284 [80-6] DEBUG IDACall - Header Name:Value pair: referer:http://127.0.0.1:8080/index.html?gwt.codesvr=127.0.0.1:9997
            === 2012-09-20 12:16:21,286 [80-6] DEBUG IDACall - Header Name:Value pair: content-length:1180
            === 2012-09-20 12:16:21,286 [80-6] DEBUG IDACall - Header Name:Value pair: cookie:GLog=%7B%0D%20%20%20%20left%3A960%2C%20%0D%20%20%20%20top%3A0%2C%20%0D%20%20%20%20width%3A940%2C%20%0D%20%20%20%20height%3A919%2C%20%0D%20%20%20%20priorityDefaults%3A%7B%0D%20%20%20%20%20%20%20%20Log%3A4%0D%20%20%20%20%7D%2C%20%0D%20%20%20%20defaultPriority%3A4%2C%20%0D%20%20%20%20trackRPC%3Atrue%0D%7D; JSESSIONID=2B62F007F075DD882A1FB8D4ABACA83F; isc_cState=ready
            === 2012-09-20 12:16:21,288 [80-6] DEBUG IDACall - Header Name:Value pair: pragma:no-cache
            === 2012-09-20 12:16:21,288 [80-6] DEBUG IDACall - Header Name:Value pair: cache-control:no-cache
            === 2012-09-20 12:16:21,288 [80-6] DEBUG IDACall - session exists: 2B62F007F075DD882A1FB8D4ABACA83F
            === 2012-09-20 12:16:21,288 [80-6] DEBUG IDACall - remote user: null
            === 2012-09-20 12:16:21,291 [80-6] DEBUG XML - Parsed XML from (in memory stream): 2ms
            === 2012-09-20 12:16:21,293 [80-6] DEBUG RPCManager - Processing 1 requests.
            === 2012-09-20 12:16:21,295 [80-6] DEBUG RPCManager - Request #1 (DSRequest) payload: {
                criteria:{
                    id:"81d14483-5c31-4630-8213-f3464998c0a5"
                },
                values:{
                    id:"81d14483-5c31-4630-8213-f3464998c0a5",
                    definition:"123"
                },
                operationConfig:{
                    dataSource:"attribute",
                    operationType:"update"
                },
                componentId:"isc_ListGrid_1",
                appID:"builtinApplication",
                operation:"attribute_update",
                oldValues:{
                    definition:"foo",
                    id:"81d14483-5c31-4630-8213-f3464998c0a5",
                    value:null
                }
            }
            === 2012-09-20 12:16:21,299 [80-6] INFO  IDACall - Performing 1 operation(s)
            === 2012-09-20 12:16:21,299 [80-6] DEBUG DeclarativeSecurity - Processing security checks for DataSource null, field null
            === 2012-09-20 12:16:21,299 [80-6] DEBUG DeclarativeSecurity - DataSource attribute is not in the pre-checked list, processing...
            === 2012-09-20 12:16:21,299 [80-6] DEBUG AppBase - [builtinApplication.attribute_update] No userTypes defined, allowing anyone access to all operations for this application
            === 2012-09-20 12:16:21,299 [80-6] DEBUG AppBase - [builtinApplication.attribute_update] No public zero-argument method named '_attribute_update' found, performing generic datasource operation
            === 2012-09-20 12:16:21,300 [80-6] DEBUG ValidationContext - [builtinApplication.attribute_update] Adding validation errors at path '/attribute/id': {errorMessage=Must be a whole number.}
            === 2012-09-20 12:16:21,301 [80-6] INFO  Validation - [builtinApplication.attribute_update] Validation error: [
                {
                    id:{
                        errorMessage:"Must be a whole number."
                    }
                }
            ]
            === 2012-09-20 12:16:21,302 [80-6] DEBUG RPCManager - Content type for RPC transaction: text/plain; charset=UTF-8
            === 2012-09-20 12:16:21,305 [80-6] DEBUG RPCManager - non-DMI response, dropExtraFields: true
            === 2012-09-20 12:16:21,307 [80-6] INFO  Compression - /test/sc/IDACall: 201 -> 173 bytes
            === 2012-09-20 12:16:21,879 [80-6] INFO  RequestContext - URL: '/test/sc/system/reference/skin/images/server_client_exchange.png', User-Agent: 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2) Gecko/20100101 Firefox/10.0.2': Moz (Gecko) with Accept-Encoding header
            === 2012-09-20 12:16:21,880 [80-6] INFO  Download - File C:/Projekte/test/smartgwtee-3.0p/samples/test/out/artifacts/test_war_exploded/test/sc/system/reference/skin/images/server_client_exchange.png not found, sending 404
            === 2012-09-20 12:16:22,019 [80-6] INFO  RequestContext - URL: '/test/sc/system/reference/skin/images/server_client_exchange.png', User-Agent: 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2) Gecko/20100101 Firefox/10.0.2': Moz (Gecko) with Accept-Encoding header
            === 2012-09-20 12:16:22,020 [80-6] INFO  Download - File C:/Projekte/test/smartgwtee-3.0p/samples/test/out/artifacts/test_war_exploded/test/sc/system/reference/skin/images/server_client_exchange.png not found, sending 404

            Comment


              #7
              Have you tried using String java type for Attribute.id field? Just like below:

              Code:
              @Id
              @GeneratedValue(generator = "uuid")
              @GenericGenerator(name = "uuid", strategy = "uuid2")
              @Column(updatable = false, length = 36)
              private String id;
              Error you're getting tells that value "81d14483-5c31-4630-8213-f3464998c0a5" cannot be assigned to property of Long type.

              Comment


                #8
                Right, I use string, because a UUID is represented by a String. Thats why I didn't defined it as Sequence.
                I think smartgwt should also honour the @Generated Annotation, no matter of what type the field is.

                Comment


                  #9
                  I'm not sure I understand what you're saying smartgwt should take care of.

                  Are you still experiencing any issues with update operation?

                  Comment


                    #10
                    1. I can't change a UUID-Field to type Long.
                    2. If the PK can't be of type Long I can't use type=sequence
                    3. If the PK is not a sequence smartgwt expect an value from the client
                    4. The uuid is generated by hibernate, so I don't need to populate this field in the client. Hibernate will give it an UUID while saving the Entity.

                    Comment


                      #11
                      Ok, let's break this down. I've tried this and it works just fine for me.

                      1. In database I have PK field of varchar type. I am using PostgreSQL, but it does not matter really.

                      2. Hibernate mapping for PK field as follows:
                      Code:
                      <id name="id" type="string">
                        <generator class="uuid"/>
                      </id>
                      3. DSField config:
                      Code:
                      <field name="id"    type="sequence" hidden="true"   primaryKey="true" />
                      4. Entity bean declares "id" field as String:
                      Code:
                      private String id;
                      Both add & update operations work fine as expected.
                      Hope this will help!

                      Comment


                        #12
                        Hello,

                        the configuration seems to be ok. but in my case there is an validation on de primary key for an integer. Even in the client the UUID is marked invalid if i doesn't hide the id column.
                        Perhaps you disabled this validation somewhere?

                        Comment


                          #13
                          Here is a screen of the UI with the loaded Datasource (showed in Firebug)
                          Attached Files

                          Comment


                            #14
                            Hi,

                            Yes, you are right: it does not work as you expect.
                            Main reason: current notion of field type "sequence" is
                            sequence=integer+(auto-increment)

                            As a workaround you can do following:

                            set field type to "text":
                            Code:
                            <field name="id"    type="text" hidden="true"   primaryKey="true" />
                            add following property to your server.properties file:
                            Code:
                            validate.primaryKeys.for.add: false
                            Regards,
                            Alius

                            Comment


                              #15
                              Hi,

                              I've just committed changes: added property "autoGenerated" to data source field.
                              Now your primary key should look like this:
                              Code:
                              <field name="id" type="text" autoGenerated="true" primaryKey="true" />
                              You can test it with next nightly build.

                              Regards,
                              Alius

                              Comment

                              Working...
                              X