这是我的用户实体:
@Entity
@Table(name="users")
public class User implements IBaseEntity<User> {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long userId;
@Column(unique = true)
@NotNull
private String username;
@Column(unique = true)
@NotNull
private String email;
@Column
@NotNull
private String password;
// @formatter:off
@ManyToMany(cascade = CascadeType.ALL)
@JoinTable(name = "users_roles",
joinColumns = { @JoinColumn(name = "user_id") },
inverseJoinColumns = { @JoinColumn(name = "role_id") })
// @formatter:on
private List<Role> roles = new ArrayList<Role>();
@Column
@NotNull
private Boolean locked;
...
}
这是我的角色实体:
@Entity
@Table(name="roles")
public class Role implements IBaseEntity<Role> {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long roleId;
@Column(unique = true)
@NotNull
private String name;
...
}
这是我的用户服务:
package org.quickloanconnect.service;
public interface IUsersService extends IBaseService<User>{
public void updateUserRolesById(List<Role> roles, Long userId);
...
}
这是UserServiceImpl:
@Service
@Transactional
public class UsersServiceImpl extends AbstractServiceImpl<User> implements
IUsersService {
...
@Override
@Transactional
public void updateUserRolesById(List<Role> roles, Long user_id) {
userDao.updateUserRolesById(roles, user_id);
}
...
}
这是dao:
public interface IUsersDao {
...
@Modifying
@Query("UPDATE User u SET u.roles = :roles WHERE u.userId = :userId")
public void updateUserRolesById(@Param("roles") List<Role> roles,
@Param("userId") Long userId);
...
}
当我运行此更新时,我得到以下内容:SqlExceptionHelper:没有为参数2指定值。是什么造成的?当我使用单个角色更新我的用户时,我看到一个大小为1的List正在使用正确的userId(两个参数都存在)到达dao,但更新似乎在dao级别失败,并且&#34; SqlExceptionHelper :没有为参数2和#34指定值;错误信息。