我最近一直在研究Hibernate和MVC。我按照各种教程,并尝试做了许多一对多的关系,但我不断收到以下错误信息:Spring + Hibernate无法确定类型设置
Caused by: org.hibernate.MappingException: Could not determine type for: java.util.Set, at table: Group, for column
在我的servlet-context.xml中,我有以下几点:
<beans:list>
<beans:value>com.model.Account</beans:value>
<beans:value>com.model.Group</beans:value>
</beans:list>
在我Group.class我有以下几点:
@Entity
@Table(name="Group")
public class Group {
@Id
@Column(name="group_id")
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int id;
private String objectId;
private String groupName;
private Set<Account> accountList = new HashSet<Account>();
// ... Getters and setters
@ManyToMany(cascade=CascadeType.ALL)
@JoinTable(name="objectId", [email protected](name="group_id"),
[email protected](name="objectId"))
public Set<Account> getAccountList() {
return accountList;
}
}
修订
Account.clas小号
@Entity
@Table(name="Account")
public class Account {
@Column(name="id")
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int id;
@Id
private String objectId;
@ManyToMany(cascade=CascadeType.ALL, mappedBy="accountList")
private Set<Group> groupList = new HashSet<Group>();
//...Getters and Setters
Group.class
@Entity
@Table(name="Group")
public class Group {
@Id
@Column(name="id")
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int id;
private String objectId;
private String groupName;
@ManyToMany(cascade=CascadeType.ALL)
@JoinTable(name="objectId", [email protected](name="group_id"),
[email protected](name="objectId"))
private Set<Account> accountList = new HashSet<Account>();
}
现在我得到以下错误每次我尝试从DAO实现节省时间:
Request processing failed; nested exception is org.springframework.dao.DataIntegrityViolationException: Duplicate entry '1' for key 'PRIMARY'; SQL [n/a]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: Duplicate entry '1' for key 'PRIMARY'
我相信,设置导致这个问题,但各种教程能够完成它,是否有一些额外的程序,我需要做的。
嗨,我收到一个新的外键映射例外。我是否在Account.class的字段级别上注释了我的注释?查看更新部分 – user288231
你能分享你的DAO实现的相关代码吗? –
我已修复他的问题。我不得不做一个@JsonIgnore,它崩溃了,因为它进入了一个无限循环。谢谢! – user288231