Я получаю эту ошибку при отправке формы:
org.hibernate.PersistentObjectException: отдельная сущность передана в постоянное хранилище: com.project.pmet.model.Account; Вложенное исключение: javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: отдельная сущность передана в постоянное хранилище: com.project.pmet.model.Account
Вот мои сущности:
Учетная запись:
@Entity
@DynamicInsert
@DynamicUpdate
public class Account {
@Id
@GeneratedValue
private Integer id;
@Column(nullable = false)
private String login;
@Column(nullable = false)
private String password;
@Column(nullable = false)
private String email;
@ManyToOne
@JoinColumn(name = "team_id")
private Team team;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "owner")
private List<Team> ownedTeams;
...
Команда:
@Entity
@DynamicInsert
@DynamicUpdate
public class Team {
@Id
@GeneratedValue
private Integer id;
@Column(nullable = false)
private String name;
@ManyToOne
@JoinColumn(name = "owner_id", nullable = false)
private Account owner;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "team")
private List<Account> members;
...
Здесь часть контроллера:
@ModelAttribute("team")
public Team createTeamObject() {
return new Team();
}
@RequestMapping(value = "/teams/create-team", method = RequestMethod.GET)
public String getCreateTeam(@ModelAttribute("team") Team team, Principal principal) {
logger.info("Welcome to the create team page!");
Account owner = accountService.findOneByLogin(principal.getName());
team.setOwner(owner);
team.setMembers(new AutoPopulatingList<Account>(Account.class));
return "teams";
}
@RequestMapping(value = "/teams/create-team", method = RequestMethod.POST)
public String postCreateTeam(@ModelAttribute("team") Team team) {
logger.info("Team created!");
teamService.save(team);
return "redirect:/teams.html";
}
И форма:
<form:form commandName="team" id="teamForm">
<div class="form-group">
<label>Name</label>
<form:input path="name" cssClass="form-control" />
</div>
<div class="form-group" id="row-template">
<label>Members</label>
<form:select path="members[0].id" cssClass="form-control" data-live-search="true" >
<form:options items="${accounts}" itemValue="id" />
</form:select>
...
</div>
<form:hidden path="owner.id" />
</form:form>
Что я делаю неправильно?