我需要将Spring Boot 1.5.10迁移到2.0,但遇到了一个问题。使用@Query注解的查询语句不能再正常工作。在1.5.10中,这些查询语句可以正常运行。以下是其中一个查询语句与实体:
@Document(collection = "credentials")
public class Credentials implements Serializable, Comparable<Credentials>
{
private static final long serialVersionUID = -921533822040690113L;
@Id
private UUID id;
@Indexed
@Field("userId")
private UUID userId;
@Field("access")
private List<Access> access;
@Field("roles")
private List<String> roles;
/**
* @return the id
*/
public UUID getId()
{
return id;
}
/**
* @param id the id to set
*/
public void setId(UUID id)
{
this.id = id;
}
/**
* @return the userId
*/
public UUID getUserId()
{
return userId;
}
/**
* @param userId the userId to set
*/
public void setUserId(UUID userId)
{
this.userId = userId;
}
/**
* @return the access
*/
public List<Access> getAccess()
{
return access;
}
/**
* @param access the access to set
*/
public void setAccess(List<Access> access)
{
this.access = access;
}
/**
* @return the roles
*/
public List<String> getRoles()
{
return roles;
}
/**
* @param roles the roles to set
*/
public void setRoles(List<String> roles)
{
this.roles = roles;
}
/**
*
*/
public Credentials()
{}
这是您需要翻译的内容:
这个查询是:
public interface ICredentialsRepository extends MongoRepository<Credentials, UUID>
{
/**
* This query finds the credentials by userId
* @param userId user identification
* @return Credentials object
*/
@Query("{ 'userId' : ?0}")
Credentials retrieveWithUserId(UUID userId);
}
运行时,我收到了错误提示。
com.mongodb.MongoQueryException: Query failed with error code 2 and error message 'unknown operator: $uuid' on server
再次强调,这在Spring Boot 1.5.10中完美运行。该项目包含spring-boot-starter-data-mongodb-2.0.0和spring-boot-configuration-processor-2.0.0。
findByUserId(UUID)
)?字符串值被序列化为BSON/JSON,MongoDB的JSON编码器创建$uuid: …
。 - mp911de