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 7773917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:14:51+00:00 2026-06-01T17:14:51+00:00

Consider the following domain models: class Sales{ String salesInvoice Customer customer } class Customer{

  • 0

Consider the following domain models:

class Sales{
    String salesInvoice
    Customer customer
}

class Customer{
    int customerNumber
    String name
}

The problem: I am trying to retrieve all the sales given a customer. Thus the code:

def sales = Sales.findAllByCustomer(Customer.get(params.id))

I don’t have problem with getting the customer. But when I use println sales.dump() I get something like

<java.util.ArrayList@d3a25f8 elementData=[mypackage.Sales : null, mypackage.Sales : null] size=2 modCount=3>

If I understand correctly, this means that the query was able to get a list of Sales but what I don’t quite understand is why is it returning a list of nulls? I’ve tried eager fetching but I don’t think that will work in this particular problem. So how to I get a list of non-null Sales objects?

  • 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-01T17:14:52+00:00Added an answer on June 1, 2026 at 5:14 pm

    The objects you have shown are not NULL, but the id of the objects is currently NULL: Each grails domain object has a toString() method which will print ${name of the class} : ${id of the instance}. If you receive outputs, like you have shown, it generally means, that your instances are existing (otherwise a NPE would have been thrown!), however the id is not yet fetched from the DB.

    1. I guess you are creating the objects in the code before. You need to flush the context, otherwise id’s are not created.
    2. You should declare, that your Sale belongs to a Customer. http://grails.org/doc/latest/guide/GORM.html#manyToOneAndOneToOne

    BTW: Name you domain classes in singular. So rename Sales to Sale.

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

Sidebar

Related Questions

Consider following program: static void Main (string[] args) { int i; uint ui; i
Consider the following domain classes class Business{ static hasMany = [contacts:ContactPerson] } class ContactPerson{
Consider following example : public class SomeBusinessLayerService : DataService<MyEntityContainer> { [WebInvoke] void DoSomething(string someParam)
Consider following class class test { public: test(int x){ cout<< test \n; } };
consider the following simplified example: public class Ticket { public int Id; public TicketState
please consider following code #include <iostream> using namespace std; class Digit { private: int
Consider following: $(#myform).attr({ action: @Url.Action(MVC.Thing.Delete().AddRouteValue(id, myJsModel.Id )) }); I'm trying to set the action
Consider the following template class class MyClassInterface { public: virtual double foo(double) = 0;
Consider following code for an android app; private String GetDistance(String src, String dest) {
Consider the following PHP snippet: <?php class Is { function __get($key) { $class =

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.