First experience with Google App Engine

14 / Sep / 2010 by Imran Mir 0 comments

A few days back I had chance to work on a googleApp using GORM-JPA plugin,version (0.7.1). I came across a few problems which are as given below.
Consider the domain : Country -> has many States.

  • At first it appeared that the one to many relationships are to be managed using annotations like :
  • Country {
      @OneToMany(mappedBy = "state")
      List states
    }
    
    State state {
      @ManyToOne
      State state
    }
    
  • The Country.get() worked fine but State.get() did not work. I think it is due to the fact that Big Table stores states as multivalued attributes of the Country. So to make it work I myself added a field (countryId) to State domain, storing the Id of the Country it belongs to as foreign key. So everytime I needed to find the State from its Id attribute, I first used to search all the States belonging to a Country, and then from these states search for a state with a particular id.
  •  List states = State.findAll("SELECT s FROM State s WHERE s.countryId='${params.countryId}'")
     def pollOptionInstance = pollOptions.find {it.id == params.id.toLong()} 
    
  • Domain.findAllBy() and Domain.findBy() do not seem to work. I used Domain.findAll{query} most of the time to query a domain.
  • Each save() operation needs to be contained in a transaction
  • Only one object can be saved in one transaction
  • I couldn’t save State object with the reference of the Country object in it. It did not allow me, so I stored the countryId instead of the whole object (which exactly is what gorm does for you). So this meant I had to manage hasMany relationships on my own, by storing the refenceIds instead of the objects itself (so annotations were of no use).
  • Hope this helps. You are welcome to share your thoughts on it.

    Imran Mir
    imran@intelligrap.com

    FOUND THIS USEFUL? SHARE IT

    Leave a Reply

    Your email address will not be published. Required fields are marked *