1

I'm playing with Xtend, and have hit a roadblock.

My class uses a Spring Data repository. Here's the interface:

public interface UserRepository extends GraphRepository<UserNode>, RelationshipOperationsRepository<UserNode> {
        public UserNode findByEntityId(Long entityId);
}

the super interface of GraphRepository<T> (which is part of Spring Data, not my project) declares the following:

@Transactional
<U extends T> U save(U entity);

@Transactional
<U extends T> Iterable<U> save(Iterable<U> entities);

However, the following code fails for me:

// UpdateUserProcessorExample.xtend
class UpdateUserProcessorExample {
    @Autowired
    UserRepository repository

    def updateUser()
    {
        var user = repository.findByEntityId(1L)
        // The following line generates an error:
        repository.save(user)
    }
}

This generates:

Bounds mismatch: The type argument is not a valid substitute for the bounded type parameter of the method save(Iterable)

It appears as though Xtend is picking the wrong overloaded method.

I've tried adding type hints, ala:

var UserNode user = repository.findByEntityId(1L)

But this still generates the same error. What am I doing wrong here?

Marty Pitt
  • 28,822
  • 36
  • 122
  • 195

2 Answers2

2

On the Xtend mailing list, Sven advised he's raised a bug for this issue:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=413138

He also offered the following work-around:

A not so nice solution is to override the respective methods in UserRepository and replace T by UserNode, like this :

public interface UserRepo extends GraphRepository<UserNode> {
    UserNode findByEntityId(Long entityId);

    @Override UserNode save(UserNode entity);

    @Override <U extends UserNode> Iterable<? extends U> save(Iterable<? extends U> entities);
Marty Pitt
  • 28,822
  • 36
  • 122
  • 195
1

I don't understand why you have introduced additional type parameters on the methods, can't you you just use the one from the class level?

@Transactional
T save(T entity);

@Transactional
Iterable<? extends T> save(Iterable<? extends T> entities);

That should work.

Sven Efftinge
  • 3,065
  • 17
  • 17
  • `GraphRepository`, which declares the methods you mention, is part of Spring Data, not my project. (Apologies if that wasn't clear). – Marty Pitt Jul 17 '13 at 09:57