I have problem because when I try update user occure 500 Internal Server Error.
RestController
@ResponseBody
@RequestMapping(value = {"/user/update"}, method = RequestMethod.POST)
public ResponseEntity<User> updateUser(@PathVariable("id_user") Long id_user, @RequestBody User userJSON) {
User currentUser = userService.findUser(userJSON.getId());
///.........../////////
return new ResponseEntity<User>(currentUser, HttpStatus.OK);
}
Routing
.when('/user/update/:id_user', {
title: 'update',
templateUrl: 'views/user.html',
controller: 'UserEditController'
Service
angular.module('app.services').factory('User', function ($resource) {
return $resource('user/:id_user', {id_user: '@_id_user'}, {
//....//
update: {
method: 'POST',
url: '/user/update/:id_user'
}
});
});
Controller
.controller('UserEditController', function($scope, $location, $routeParams, User) {
$scope.updateUser = function() {
$scope.user.$update(function() {
$location.path('/user');
});
};
$scope.loadUser = function() {
$scope.user = User.get({ id_user: $routeParams.id_user });
};
$scope.loadUser();
});
This is my button for edit user
<div class="col-sm-12 controls">
<a class="btn btn-danger" href="/user/update/{{currentUser.id}}" ng-click="updateUser()">Save</a>
</div>
UserServiceImpl
public void updateUser(User user) {
User entity = userDao.findUser(user.getId());
if (entity != null) {
entity.setLogin(user.getLogin());
entity.setPassword(user.getPassword());
entity.setEmail(user.getEmail());
entity.setAuthority(user.getAuthority());}}
AbstractDao:
public void save(T entity) {
getSession().saveOrUpdate(entity);}
public void merge(T entity) {
getSession().merge(entity);}
UserDaoImpl:
public void saveUser(User user) {
if (user.getId() != null){
merge(user);
}else {
save(user);
}
}
User:
@Entity
@Table(name = "USERS")
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
public class User implements Serializable {
private static final long serialVersionUID = -935756135185747853L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(nullable = false, unique = true)
private String login;
private String password;
private String email;
private Boolean enabled = true;
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
private Set<Authority> authority = new HashSet<Authority>();
//....getter and setter...../
Request JSON:
authority: [{id: 1, authority: "USER", user: 1}]
email: "a"
enabled: true
id: 1
login: "add"
password: "add"
I will be grateful for your help.