I have the following bean:
public class TerminalAdmin {
@Id
@Column(name = "admin_id", nullable = false, unique = true)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "user_id")
@SequenceGenerator(name = "user_id", sequenceName = "user_id")
private Long adminId;
@Column(name = "email", nullable = false)
private String email;
@Column(name = "phone")
@Size(max = 255)
private String phone;
@Size(max = 255)
@Column(name = "name")
private String name;
@Column(name = "registration_date")
@Temporal(TemporalType.TIMESTAMP)
private Calendar createDate;
@Column(name = "password", nullable = false)
@Size(min=1, max = 255, message = "введите пароль длиной от 1 до 255 символов")
private String password;
@ManyToMany(fetch=FetchType.EAGER,cascade=CascadeType.ALL)
@JoinTable(name = "admin_role", joinColumns = {
@JoinColumn(name = "admin_id", nullable = false) },
inverseJoinColumns = { @JoinColumn(name = "role_id",
nullable = false) })
private Set<AdminRole> adminRoles;
@Column(name = "blocked")
private boolean blocked;
...
}
and this:
public class AdminRole {
@Id
@Column(name = "role_id", nullable = false, unique = true)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "user_id")
@SequenceGenerator(name = "user_id", sequenceName = "user_id")
private Long id;
@Column(name = "role")
private String role;
....
}
Inside controller:
@RequestMapping(value = "/admin/addNewAdmin")
public String adminUsers(@Valid TerminalAdmin terminalAdmin,
BindingResult bindingResult, ModelMap model, Principal principal, HttpSession session) {
from client side I send following request:
terminalAdmin comes to the method looks like this
- Why spring writes values into
role
field? - How to force spring write
250
/251
into id field?
P.S.
I tried to write
InitBinder
public void initBinder(WebDataBinder binder) {
binder.registerCustomEditor(AdminRole.class, new PropertyEditorSupport() {
public void setAsText(String name) {
....
}
});
}
but setAsText
method doesn't invoke.