gorm - How to implements tablePerHierarchy with disciminator in grails? -
i have class hirarchy :
class item {} class participation extends item{} class contribution extends participation{} class question extends participation{}
i have table per class so, add tableperhierarchy false in item
i need discrimator implements query : class = "contribution"
i try lot of implementation it's not working.
how ?
thanks
do want table per hierarchy or table per class? it's not clear in question.
with following domain objects, can either way:
// item.groovy class item { string x } // participation.groovy class participation extends item { string y }
using default, table per hierarchy strategy, 1 table used store items , subclasses of items too. default discriminator column called class
, grails use automatically. schema generated grails schema-export
looks this:
create table item ( id bigint generated default identity (start 1), version bigint not null, x varchar(255) not null, class varchar(255) not null, y varchar(255), primary key (id) );
there's 1 table both classes contains fields declared in every class in hierarchy plus discriminator column class
. if query participation.list()
, sql grails generates looks this:
select this_.id id1_0_, this_.version version1_0_, this_.x x1_0_, this_.y y1_0_ item this_ this_.class='participation'
by changing inheritance strategy table per class static mapping { tableperhieracrchy false }
in item.groovy, grails generate table each of classes in hierarchy. each table stores fields declared in each class, participation object represented row in both item table , participation table. schema looks this:
create table item ( id bigint generated default identity (start 1), version bigint not null, x varchar(255) not null, primary key (id) ); create table participation ( id bigint not null, y varchar(255) not null, primary key (id) );
and sql participation.list()
changes to:
select this_.id id1_0_, this_1_.version version1_0_, this_1_.x x1_0_, this_.y y2_0_ participation this_ inner join item this_1_ on this_.id=this_1_.id
Comments
Post a Comment