Derived property calling stored function throws StreamCorruptedException

Charles Wood

I'm trying to improve performance by replacing a dynamic field (a transient getter with no underlying database representation) with a derived field so that I can use, e.g., Criteria to query my model. The original dynamic field was pretty simple:

Client resolveClient() {
    if (prevCall && prevCall.client) {
        return prevCall.client
    } else {
        return client
    }
}

I don't know how to reproduce that with a single MySQL statement, so I figured I would go ahead and stick it into a stored function, defined as follows:

CREATE FUNCTION `request_client`(requestId long) RETURNS varchar(255) CHARSET utf8
begin
    declare pci long;
    declare clientId long;
    declare clientName varchar(255);

    select request.prev_call_id
    from request
    where request.id = requestId
    into pci;

    if pci is not null then
      select call_history.client_id
      from call_history
      where call_history.call_id = pci
      into clientId;
    else
      select request.client_id
      from request
      where request.id = requestId
      into clientId;
    end if;

    select clients.client_name
    from clients
    where clients.client_id = clientId
    into clientName;

    return clientName;

  end;

And then I call that function in a derived field:

String derivedFieldName
static mapping = {
    derivedFieldName formula: '(select stored_function(id))'
}

The problem is that now when I run any query on the domain, even as simple as Request.list(), I get the following exception:

Class: java.io.StreamCorruptedException
Message: invalid stream header: 32303135

For extra fun, this is an abstract domain class. I don't know if that really makes any difference; it's still persisted to the database like any other domain, and I'm calling the query on the abstract class itself, not an implementation.

The most frustrating thing is that the derived field itself does work! I can successfully retrieve a client name using it; I just can't query the overall domain.

Finally, I am pretty confident that the derived property is the issue, as I have commented it out and can then successfully query the domain.

Charles Wood

If anybody comes across this later, the problem actually was the abstract class. And not just that it's an abstract class -- it's an abstract domain class. Apparently, Grails doesn't support derived properties on those.

To move querying to the database I just had to start saving the resolved client into my Request domain :/

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

calling function stored as a property in an object in a for loop

From Dev

Reusing ObjectInputStream throws StreamCorruptedException

From Dev

calling a base function on a derived object

From Dev

Calling base function from derived

From Dev

Calling the templated function of a derived type

From Dev

Base Class Function Not Calling Derived Class Function

From Dev

Calling a function that's stored in a map

From Dev

MySql - Creating Stored Function and Calling It

From Dev

Calling a stored function that returns nothing

From Dev

typescript parent class is calling derived function

From Dev

Calling derived class function using abstract pointer

From Dev

Calling Entity's function with a derived class

From Dev

Calling a derived function from an array of the base class

From Dev

Calling component function throws "is not a function" exception

From Dev

MySQL Throws an Error IF Function in Stored Procedure

From Dev

calling javascript from gwt throws undefined is not a function

From Dev

Cython: calling C function throws 'undefined symbol'

From Dev

Calling lean on document throws TypeError: lean is not a function

From Java

Why is "throws Exception" necessary when calling a function?

From Dev

Calling function inside callback throws error in Angular

From Dev

Graphviz throws errors calling view() function

From Dev

Calling function from within class throws NameError

From Dev

Calling any function from dll throws error

From Dev

Typescript throws no error when calling nullable function

From Dev

Calling a function and property the same way?

From Dev

Calling a model method as property and not a function

From Dev

Calling function on a nested Objects property?

From Dev

overloading virtual function and calling derived function by pointer to base class

From Dev

JavaScript: Access 'this' when calling function stored in variable

Related Related

  1. 1

    calling function stored as a property in an object in a for loop

  2. 2

    Reusing ObjectInputStream throws StreamCorruptedException

  3. 3

    calling a base function on a derived object

  4. 4

    Calling base function from derived

  5. 5

    Calling the templated function of a derived type

  6. 6

    Base Class Function Not Calling Derived Class Function

  7. 7

    Calling a function that's stored in a map

  8. 8

    MySql - Creating Stored Function and Calling It

  9. 9

    Calling a stored function that returns nothing

  10. 10

    typescript parent class is calling derived function

  11. 11

    Calling derived class function using abstract pointer

  12. 12

    Calling Entity's function with a derived class

  13. 13

    Calling a derived function from an array of the base class

  14. 14

    Calling component function throws "is not a function" exception

  15. 15

    MySQL Throws an Error IF Function in Stored Procedure

  16. 16

    calling javascript from gwt throws undefined is not a function

  17. 17

    Cython: calling C function throws 'undefined symbol'

  18. 18

    Calling lean on document throws TypeError: lean is not a function

  19. 19

    Why is "throws Exception" necessary when calling a function?

  20. 20

    Calling function inside callback throws error in Angular

  21. 21

    Graphviz throws errors calling view() function

  22. 22

    Calling function from within class throws NameError

  23. 23

    Calling any function from dll throws error

  24. 24

    Typescript throws no error when calling nullable function

  25. 25

    Calling a function and property the same way?

  26. 26

    Calling a model method as property and not a function

  27. 27

    Calling function on a nested Objects property?

  28. 28

    overloading virtual function and calling derived function by pointer to base class

  29. 29

    JavaScript: Access 'this' when calling function stored in variable

HotTag

Archive