Announcement Announcement Module
Collapse
No announcement yet.
Owned One-to-Many Relationships for GAE not supported by Roo Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Owned One-to-Many Relationships for GAE not supported by Roo

    If I create an owned one-to-many relationship with Google App Engine as the database, using the default Long as the primary key, I get the following error:

    Code:
    Cannot have a java.lang.Long primary key and be a child object
    However, Iíve come up with a solution to get owned one-to-many to work using the Key as Encoded String strategy. The first thing I did was set the entity IDs to be a String. Here is my script:

    Code:
    persistence setup --provider DATANUCLEUS --database GOOGLE_APP_ENGINE 
    entity --class ~.server.domain.Person --identifierType java.lang.String 
    field string --fieldName firstName
    field string --fieldName lastName
    entity --class ~.server.domain.Address --identifierType java.lang.String 
    field string --fieldName streetAddress
    field string --fieldName city
    field string --fieldName state --permitReservedWords
    field string --fieldName zip
    field reference --fieldName person --type Person
    focus --class Person
    field set --fieldName addresses --element Address --cardinality ONE_TO_MANY --mappedBy person
    gwt setup
    Then I created an aspect to add the extension for encoded string to the entity id and an auto incrementing Long.

    Code:
    package com.test.server.domain;
    
    import org.datanucleus.jpa.annotations.Extension;
    
    privileged aspect Person_Roo_GAE {
    	
        declare @field: * Person.id: @Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true");
    
        @Extension(vendorName="datanucleus", key="gae.pk-id", value="true")
        private Long Person.autoId;
    
        public Long Person.getAutoId() {
            return this.autoId;
        }
        
        public void Person.setAutoId(Long autoId) {
            this.autoId = autoId;
        }
        
    }
    Code:
    package com.test.server.domain;
    
    import org.datanucleus.jpa.annotations.Extension;
    
    privileged aspect Address_Roo_GAE {
    
        declare @field: * Address.id: @Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true");
    
        @Extension(vendorName="datanucleus", key="gae.pk-id", value="true")
        private Long Address.autoId;
    
        public Long Address.getAutoId() {
            return this.autoId;
        }
        
        public void Address.setAutoId(Long autoId) {
            this.autoId= autoId;
        }
    
    }
    And with that minor mod, the scaffold works perfectly with GAE.
    Last edited by jaredrowell; Oct 28th, 2010, 05:02 PM.

  • #2
    Putting in this change...thanks for the note!

    Comment


    • #3
      Looks like a bug

      If long is not supported in datanucleus as Key, then Key should be default when using datanucleus, I think.

      Comment


      • #4
        Workaround

        Is there any way to workaround this issue? How do I change the default id generation, so that instead of generating id with Long generates ids with Key, or String?

        Comment


        • #5
          This is fixed in master and will be included in the next release of Roo. The related ticket has been closed here.

          Comment


          • #6
            James,

            It is very unclear for me HOW this problem has been solved in the latest release (1.1.1). Nothing in the JIRA ticket, nor in the different posts of this forum, nor in ANY document gives a clear guidance about how to proceed. The use of com.google.appengine.api.datastore.Key doesn't work.
            Could you give any guidance/link about how to REALLY manage owned OneToMany relationships in GAE ?

            Thanks in advance.

            Comment


            • #7
              I don't think it's entirely fixed

              I tried creating a new project based on jaredrowell's script and using the latest roo from git (1.1.2.BUILD-SNAPSHOT [rev 6c006f1]). It still fails because the primary key of Address is a long.

              Like cyrille, I would like to know if there is a way to make one to many owned relationships work on GAE ?

              Comment


              • #8
                I've dug into it and it seems there is a regression in 1.1.2.BUILD-SNAPSHOT [rev 6c006f1].
                I tried with 1.1.1.RELEASE [rev 156ccd6] and I don't get the Long id error.
                (but I do get the hardcoded Employee error )

                @cyrille : unfortunately, it is said in the JIRA ticket that the chosen solution is to make all relationships unowned.

                Comment


                • #9
                  Have the same error with the hardcore "employee" error when i implement a set or a reference field :'(

                  Comment


                  • #10
                    I use 1.1.2.RELEASE.
                    Have an error: "Cannot have a java.lang.Long primary key and be a child object" for ManyToOne relationship.


                    entity --class ~.domain.Author --testAutomatically
                    field string --fieldName name --notNull --sizeMax 25

                    entity --class ~.domain.Note --testAutomatically
                    field string --fieldName text --notNull --sizeMax 256
                    field reference --fieldName author --type ~.domain.Author

                    Comment


                    • #11
                      Well, for me, i'll wait until a stable version of spring roo will be avalaible.
                      Here, it would seem it's in beta version yet with these recurrent errors for relation many to one (or many)...

                      Comment


                      • #12
                        Roo 1.1.2 release is out, and there are still problems with One-to-Many relationships for GAE...

                        I have opened a bug in Jira: https://jira.springsource.org/browse/ROO-2211

                        There is no easy work-around, since when you set an entity's id type to Long, it breaks the gae.encoded-pk requirement, and if you set the id type to String, you break other code that is expecting Long ids (such as *MobileListView.java's primaryRenderer)...

                        :-(
                        Last edited by mrsvan; Mar 7th, 2011, 03:46 PM.

                        Comment


                        • #13
                          this is related to a GAE limitation as it require encoded string for any serious entity relationship
                          so ROO have to change the assumption that the primary key (ID field) is of type Long

                          Joe

                          Comment

                          Working...
                          X