Is it possible in grails to disable persistence of a domain class dynamically with inheritance

被刻印的时光 ゝ 提交于 2019-12-08 09:10:13

问题


My question is related to/or identical to Is it possible in grails to disable persistence of a domain class?

I am using grails 2.2.1 where I tried to turn off a domain class by putting static mapWith = "none" gorm creates the database table, and calling .save() will actually put an entry to the database. So the mapWith flag did nothing for me. I also cannot find any documentation regarding the mapWith flag. Is there a replacement in Grails 2?

Update on sept 16 with code

package test

class Person {


  String name
  static constraints = {
  }

  static mapping = {
    version false
    tablePerHierarchy false
    table 'psn'
  }
}
-------------------

package test

class Employer extends Person{

  static mapWith = 'none'

  String title
  static constraints = {

  }

  static mapping = {
    version false
    tablePerHierarchy false
    table 'emplyr'
  }
}

---------
package test

class Employee extends Person{


  String description

  static constraints = {
  }

  static mapping = {
    version false
    tablePerHierarchy false
    table 'emplyee'
  }
}

I would assume Employer should not be treated as a domain object. However, when I perform, a Person.list(), this sql was shown:

Hibernate: select this_.id as id0_0_, this_.name as name0_0_, this_1_.description as descript2_1_0_, this_2_.title as title2_0_, case when this_1_.id is not null then 1 when this_2_.id is not null then 2 when this_.id is not null then 0 end as clazz_0_ from psn this_ left outer join emplyee this_1_ on this_.id=this_1_.id left outer join emplyr this_2_ on this_.id=this_2_.id limit ?
Hibernate: select count(*) as y0_ from psn this_ left outer join emplyee this_1_ on this_.id=this_1_.id left outer join emplyr this_2_ on this_.id=this_2_.id

Why would it join emplyr????? My purpose is to eliminate this table join when this is mark as "none". Am I doing something wrong?

来源:https://stackoverflow.com/questions/18411469/is-it-possible-in-grails-to-disable-persistence-of-a-domain-class-dynamically-wi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!