0

I've got a handful of classes (simplified) in grails 2.5.5:

class Solution implements Serializable {
    long id
    String name

    static hasOne = [
        entity : SolutionEntity
    ]

    static mapping = {
        datasource 'companion'
        id generator:'sequence', params:[sequence: 'SOLUTION_SEQ']
        entity cascade: 'delete'
    }

    static constraints = {
        name nullable: true, blank:false, unique: true
        entity nullable: true
    }
}

class SolutionEntity implements Serializable {
    Solution solution

    Long externalEntityId
    private Object externalEntity

    void setExternalEntity(def value){
        externalEntityId = value.id
    }

    static transients = ["externalEntity"]

    static constraints = {
        solution nullable: false, unique: true
        externalEntityId nullable: false
    }

    static mapping = {
        datasource 'companion'
        id generator:'sequence', params:[sequence: 'SOLUTION_ENTITY_SEQ']
        tablePerHierarchy true
    }
}

class SolutionPPB extends SolutionEntity implements Serializable {

    PPB getPPB(){
        if(!externalEntity && externalEntityId) {
            externalEntity = PPB.get(externalEntityId)
        }
        externalEntity
    }

    static constraints = {
    }
}

where the basic idea is that I want to associate each Solution with a SolutionEntity, which may be of different types (I've shown PPB here). This is based on Burt Beckwith's recommendation because the PPB are in different datasources. I'm able to create and modify Solution entries as I like, there doesn't seem to be any problem there. However, when I try to create a SolutionEntity object like this:

def link = SolutionPPB.findOrCreateBySolution(solution)
link.setExternalEntity(entity)
link.save(failOnError: false)

I get the exception:

org.springframework.orm.hibernate4.HibernateSystemException: Unknown entity: myapp.Solution; nested exception is org.hibernate.MappingException: Unknown entity: myapp.Solution

I can't figure out what I'm doing wrong. It seems surprising that Solution is unknown since I didn't have any trouble making the Solution before trying to link it.

amos
  • 5,092
  • 4
  • 34
  • 43
  • More than a guess, but can you replace entity for something else like solutionEntity? – Fran García Jun 23 '17 at 05:24
  • I would also change the class name SolutionEntity to something else. – Fran García Jun 23 '17 at 08:25
  • I've tried 3 variants: one with the text "entity" substituted to something else (this still failed), and another w/o the subclasses (this worked), and I also tried removing the SolutionEntity references from Solution (didn't work). While it would be nice to do inheritance, I think I need to skip it for now. – amos Jun 23 '17 at 14:04
  • where is the PPB class? – Fran García Jun 26 '17 at 08:24
  • It's in a different DataSource (and I can't put all of these in the same DataSource), but there's nothing fancy about it -- I just want to record associations between a PPB and a Solution. – amos Jun 27 '17 at 11:53

0 Answers0