Page 1 of 2 12 LastLast
Results 1 to 10 of 13

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

  1. #1
    Join Date
    Oct 2010
    Posts
    3

    Default 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 at 04:02 PM.

  2. #2
    Join Date
    Sep 2010
    Posts
    3

    Default

    Putting in this change...thanks for the note!

  3. #3
    Join Date
    Nov 2010
    Posts
    2

    Default Looks like a bug

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

  4. #4
    Join Date
    Nov 2010
    Posts
    1

    Default 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?

  5. #5

    Default

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

  6. #6
    Join Date
    Jan 2011
    Posts
    17

    Default

    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.

  7. #7

    Default 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 ?

  8. #8

    Default

    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.

  9. #9
    Join Date
    Feb 2011
    Posts
    8

    Default

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

  10. #10
    Join Date
    Oct 2010
    Posts
    5

    Default

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •