org.hibernate.MappingException: Could not determine type for: java.util.List, at table: user, for columns: [org.hibernate.mapping.Column(events)]
它给了我下面的错误。
1 | org.hibernate.MappingException: Could not determine type for: java.util.List, at table: user, for columns: [org.hibernate.mapping.Column(events)] |
这里是我的代码
java用户:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | import com.google.common.base.Objects; import java.util.List; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; @Entity public class User { @Id @NotNull @Size(max = 64) @Column(name ="id", nullable = false, updatable = false) private String id; @NotNull @Size(max = 64) @Column(name ="name", nullable = false) private String name; @NotNull @Size(max = 64) @Column(name ="firstname", nullable = false) private String firstname; @NotNull @Size(max = 64) @Column(name ="email", nullable = false) private String email; @NotNull @Size(max = 64) @Column(name ="password", nullable = false) private String password; private List<Events> events; public User() { } public User(String id, String name, String firstname, String email, String password) { super(); this.id = id; this.name = name; this.firstname = firstname; this.email = email; this.password = password; } public void setId(String id) { this.id = id; } public String getId() { return id; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getFirstname() { return firstname; } public void setFirstname(String firstname) { this.firstname = firstname; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public List<Events> getEvents() { return events; } public void setEvents(List<Events> events) { this.events = events; } @Override public String toString() { return Objects.toStringHelper(this).add("id", id).add("name", name).add("firstname", firstname) .add("email", email).add("password", password).add("events", events).toString(); } } |
号
事件.java:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | public class Events { public Events() { } private String startEvent; private String endEvent; public String getStartEvent() { return startEvent; } public void setStartEvent(String startEvent) { this.startEvent = startEvent; } public String getEndEvent() { return endEvent; } public void setEndEvent(String endEvent) { this.endEvent = endEvent; } } |
事件不应存储在数据库中
从代码的外观来看,在我看来,事件不应该存储在数据库中。
如果是这种情况,那么标记它们就足够了@transient
1 2 | @Transient private List<Events> events; |
。
如果需要存储在数据库中,则需要为
1 2 | @OneToMany private List<Events> events; |
或
1 2 3 | @OneToMany @JoinColumn private List<Events> events; |
号
并将
1 2 3 4 |