这是我的类用户和目录...一个用户有很多目录。
package com.egs.account.model;
import org.apache.commons.lang.builder.EqualsBuilder;
import javax.persistence.*;
import java.util.Date;
import java.util.Set;
@Entity
@Table(name = "user")
public class User {
private Long id;
private String username;
private String password;
private String passwordConfirm;
private String firstName;
private String lastName;
private Date dateRegistered;
private Long skypeID;
private Set<Role> roles;
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL)
private Set<Catalog> catalogs;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getUsername() { return username; }
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Transient
public String getPasswordConfirm() {
return passwordConfirm;
}
public void setPasswordConfirm(String passwordConfirm) {
this.passwordConfirm = passwordConfirm;
}
public String getFirstName() { return firstName; }
public void setFirstName(String firstName) { this.firstName = firstName; }
public Date getDateRegistered() { return dateRegistered; }
public void setDateRegistered(Date dateRegistered) { this.dateRegistered = dateRegistered; }
public Long getSkypeID() { return skypeID; }
public void setSkypeID(Long skypeID) { this.skypeID = skypeID; }
public String getLastName() { return lastName; }
public void setLastName(String lastName) { this.lastName = lastName; }
public Set<Role> getRoles() {
return roles;
}
public void setRoles(Set<Role> roles) {
this.roles = roles;
}
public Set<Catalog> getCatalogs() { return catalogs; }
public void setCatalogs(Set<Catalog> catalogs) { this.catalogs = catalogs; }
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + ((firstName == null) ? 0 : firstName.hashCode());
return result;
}
@Override
public boolean equals(final Object obj) {
if (!(obj instanceof User)) {
return false;
}
if (obj == this) {
return true;
}
final User other = (User) obj;
final EqualsBuilder builder = new EqualsBuilder();
builder.append(this.firstName, other.firstName);
builder.append(this.lastName, other.lastName);
builder.append(this.username, other.username);
builder.append(this.skypeID, other.skypeID);
return builder.isEquals();
}
@Override
public String toString() {
return "UserDocument [id=" + id + ", name=" + firstName + ", lastName="
+ lastName + ", username=" + username + "]";
}
}
这个是目录类。
package com.egs.account.model;
import javax.persistence.*;
import java.util.Date;
@Entity
@Table(name = "user")
public class Catalog {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String link;
private String comment;
private Date insertDate;
@ManyToOne(optional = false)
@JoinColumn(name = "USER_ID")
private User user;
@Lob @Basic(fetch = FetchType.LAZY)
@Column(name="content", nullable=false)
private byte[] content;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getLink() { return link; }
public void setLink(String link) { this.link = link; }
public String getComment() { return comment; }
public void setComment(String comment) { this.comment = comment; }
public Date getInsertDate() { return insertDate; }
public void setInsertDate(Date insertDate) { this.insertDate = insertDate; }
public User getUser() { return user;}
public void setUser(User user) { this.user = user; }
public byte[] getContent() { return content; }
public void setContent(byte[] content) { this.content = content; }
}
运行我的应用程序时,我遇到了这种异常。
引起:org.hibernate.MappingException:无法确定类型:java.util.Set,在表:user,对于列:[org.hibernate.mapping.Column(catalogs)]
任何人请告诉我这段代码有什么问题。