Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tuple entity is taken by the type of the repository, and not by the type of return of the function #32

Closed
ArtDu opened this issue Mar 9, 2021 · 3 comments
Labels
enhancement New feature or request

Comments

@ArtDu
Copy link
Contributor

ArtDu commented Mar 9, 2021

public interface PetRepository extends TarantoolRepository<Pet, Integer> {

	/**
	 * Retrieve all {@link PetType}s from the data store.
	 * @return a Collection of {@link PetType}s.
	 */
//	@Query("SELECT ptype FROM PetType ptype ORDER BY ptype.name")
//	@Transactional(readOnly = true)
	@Query(function = "find_pet_types")
	List<PetType> findPetTypes();
local function find_pet_types()
    return crud.select("types")
end

image

2021-03-09 11:38:19.759 ERROR 46506 --- [nio-8080-exec-8] o.a.c.c.C.[.[.[/].[dispatcherServlet]: Servlet.service() for
 servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is
org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.util.ArrayList<?>] to type
[@org.springframework.data.tarantool.repository.Query java.util.List<org.springframework.samples.petclinic.owner.PetType>] for value '[cat, dog, lizard, snake, bird, hamster]'; 
nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of 
converting from type [org.springframework.samples.petclinic.owner.Pet] to type 
[@org.springframework.data.tarantool.repository.Query org.springframework.samples.petclinic.owner.PetType]] with root 
cause

org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type
 [org.springframework.samples.petclinic.owner.Pet] to type [@org.springframework.data.tarantool.repository.Query org.springframework.samples.petclinic.owner.PetType]
@akudiyar akudiyar added the 1sp label Mar 9, 2021
@akudiyar akudiyar added this to the Q1 2021 milestone Mar 9, 2021
@akudiyar akudiyar added the enhancement New feature or request label Mar 9, 2021
@vrogach2020
Copy link
Contributor

Also the following scenario must be fixed.
Tarantool side function:

function test_custom(a, b)
  return tostring(a + b)
end

Repository method definition

    @Query(function = "test_custom")
    String testCustom(Integer a, Integer b);

Repository usage

    @Test
    public void testCustomMethod() {
        String r = bookRepository.testCustom(1,2);
        assertEquals("3", r);
    }

Now it throws the following error:

org.springframework.dao.InvalidDataAccessResourceUsageException: The received result cannot be converted to an array of tuples: 3; nested exception is io.tarantool.driver.exceptions.TarantoolClientException: The received result cannot be converted to an array of tuples: 3

@ArtDu
Copy link
Contributor Author

ArtDu commented Nov 23, 2021

The workaround, for now, is to use the wrapper

public class StringWrapper {
    private String string;
}
public interface StringRepository extends TarantoolRepository<StringWrapper, Long> {
    @Query(function = "custom_function")
    StringWrapper customFunction();
}
@Test
public void test() {
    String s = stringRepository.customFunction();
    assertEquals("hello", s);
}
function custom_function()
    return {string = "hello"}
end

@ArtDu
Copy link
Contributor Author

ArtDu commented Dec 24, 2021

Closes by #48

@ArtDu ArtDu closed this as completed Dec 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants