Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8367485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:10:15+00:00 2026-06-09T13:10:15+00:00

I have two classes: sample, and parameter. I also have a sample_sample_parameter lookup table

  • 0

I have two classes: sample, and parameter. I also have a sample_sample_parameter lookup table which exists to hold the sample id and the parameter id. This is mapped in my grails app.

I was able to write an sql query that works in squirrel:

select s.* from sample s, sample_sample_parameters sp where s.id = sp.sample_id and sp.sample_parameter_id = 41

where 41 would be replaced with the parameter.id variable passed from the gsp page to the action. I have also tried to make it work with executeQuery but it tells me that sample is not mapped.

How do I turn this query into a gorm recognizable form?

class Sample {


Date collectionDate // date the sample was collected
Date sampleReceivedDate // date the sample arrived on site
Date dateCreated
String sampleComments // details about the sample
String labAccessionID // internal reference
String sampleGender // is it from a male or female?
String sampleAge // the age of the animal the sample was taken from
String sampleBreed // the breed of animal
String sampleNameID // patient name
String filepath

String enteredby


String sg
String mosm

static searchable = true


static hasMany =[sampleParameters:SampleParameter, ficsruns:Ficsrun]//[tags:Tag]// a Sample can have many parameters
/* mappedBy allows two tables share a common table. It creates two join tables, one for each. 
 * SampleParameter is the table being shared by Sample and SampleType tables */
static mappedBy=[sampleParameters:"samples"]//[tags:"domainClass1s"]/*http://www.van-porten.de/2010/09/multiple-many-to-many-in-grails/*/
static belongsTo = [sampleType:SampleType, labFinding:LabFinding, sampleSource:SampleSource, species:SpeciesList] // creates dependencies


static constraints = {

    sampleType(blank:false)
    sampleNameID(blank:false)
    collectionDate(blank:false)
    sampleReceivedDate(blank:false)
    sampleComments(nullable:true, maxSize:1000)
    labAccessionID(nullable:true)
    sampleGender(blank:false, inList:["M","F","NM","SF", "UNK"])
    sampleAge(nullable: true)
    sampleBreed(nullable:true)
    sampleSource(blank:false)
    species(blank:false)
    labFinding(nullable:true)
    filepath(nullable:true)
    enteredby(nullable:true)
    sg(nullable:true)
    mosm(nullable:true)
    dateCreated()
}

/* This section is for static mapping to the hematology database*/
   static mapping = {
    version false
    id generator:'sequence', params:[sequence:'SHARED_SEQ']   
   }

   String toString(){
    "${sampleNameID}"
  }
}


class SampleParameter implements Comparable{


String name
String value

static hasMany = [
samples:Sample,         //domainClass1s: DomainClass1,
sampleTypes:SampleType  //domainClass2s: DomainClass2
]
static mapping = {
    version false
    id generator:'sequence', params:[sequence:'SHARED_SEQ']   
}

  static mappedBy =        [samples:"sampleParameters",sampleTypes:"sampleParameters"]//[domainClass1s: "tags", domainClass2s: "tags"]
  static belongsTo =[Sample,SampleType] //[DomainClass1, DomainClass2]

  static constraints = {
     name(blank:false)
     //value()
     //value(unique:true)
     value (unique: 'name')
 }

@Override public String toString() {
return name + " " + value
}

@Override
public int compareTo(Object o) {
    if (o == null || this == null) {
        return 0;
    } else {
        return value.compareTo(o.value)
    }
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T13:10:17+00:00Added an answer on June 9, 2026 at 1:10 pm

    As a first suggestion, when you have the paramter’s id, do the following.

    Parameter p = Parameter.get(params.id) // or wherever your id is stored
    List<Sample> samples = Sample.findAllByParameter(p) // this assumes, the parameter property is actually named 'parameter'
    

    Of course there is no error handling in place right now, but you’ll get the idea.

    Welcome to GORM, welcome to Grails.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two classes (MVC view model) which inherits from one abstract base class.
I have placed the two bloom classes into my project from the Bloom sample
Simple Java generics question: I have two classes - one of which uses generics
I have a simple Fluent NHibernate model with two related classes: public class Applicant
I have two classes A and B generated by cxf-codegen-plugin from my WSDL. A
I have two classes Foo and Bar . The tables in the database look
I have two classes Foo and Bar that Bar extends Foo as below: class
I have two classes, Item and SoldItem . SoldItem inherits from Item adding some
I have two classes, one that inherits from the other. The base class is
I have two classes, TestA and TestB . TestA extends QObject . I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.