Rafa
Rafa

Reputation: 3339

Scala cannot resolve constructor

I'm leveraging the interoperability between Scala and Java and have the below code that uses Scala, to instantiate a class in the same project that was written in Java. The CommandExecutor parameter is inherited from a parent class.

class IdmIdentityServiceImpl extends ServiceImpl with IdmIdentityService {
    override def createNativeUserQuery: NativeUserQuery = {
        new NativeUserQueryImpl(commandExecutor)
      }
}

I get an error, in instantiating NativeUserQueryImpl that says cannot resolve constructor

NativeUserQueryImpl was written in Java, but I've been reading about the interoperability between Java and Scala and feel like it should work.

This is the NativeUserQueryImpl class, which takes in that CommandExecutor type in one of it's constructors. The class comes from the flowable-engine library.

public class NativeUserQueryImpl extends AbstractNativeQuery<NativeUserQuery, User> implements NativeUserQuery {

  private static final long serialVersionUID = 1L;

  public NativeUserQueryImpl(CommandContext commandContext) {
    super(commandContext);
  }

  public NativeUserQueryImpl(CommandExecutor commandExecutor) {
    super(commandExecutor);
  }

  // results ////////////////////////////////////////////////////////////////

  public List<User> executeList(CommandContext commandContext, Map<String, Object> parameterMap, int firstResult, int maxResults) {
    return commandContext.getUserEntityManager().findUsersByNativeQuery(parameterMap, firstResult, maxResults);
  }

  public long executeCount(CommandContext commandContext, Map<String, Object> parameterMap) {
    return commandContext.getUserEntityManager().findUserCountByNativeQuery(parameterMap);
  }

}

EDIT:

Full error

Error:(31, 5) overloaded method constructor NativeUserQueryImpl with alternatives:
  (x$1: org.flowable.idm.engine.impl.interceptor.CommandExecutor)org.flowable.idm.engine.impl.NativeUserQueryImpl <and>
  (x$1: org.flowable.idm.engine.impl.interceptor.CommandContext)org.flowable.idm.engine.impl.NativeUserQueryImpl
 cannot be applied to (org.flowable.engine.impl.interceptor.CommandExecutor)
    new NativeUserQueryImpl(commandExecutor)

Upvotes: 1

Views: 7371

Answers (1)

Rafa
Rafa

Reputation: 3339

From the full error posted in the original question, it appears that the CommandExecutor that is inherited from the parent class ServiceImpl has two different versions in the library

org.flowable.idm.engine.impl.interceptor.CommandExecutor and org.flowable.engine.impl.interceptor.CommandExecutor where the subtle difference is that one is from an idm package and one is not.

Changing ServiceImpl from the second package to the first, updates the CommandExecutor parameter that's being passed in, and fixes the issue.

Upvotes: 1

Related Questions