如果用户是上下文的管理员,我正在开发一个具有多对多关系(用户上下文之间)和附加列(isAdmin)关系的解决方案。
我遵循了本教程:
http://www.mkyong.com/hibernate/hibernate-many-to-many-example-join-table-extra-column-annotation/
但是当我刷新用户容器时,我收到了StackOverFlowException错误。
Caused by: java.lang.StackOverflowError
at oracle.jdbc.driver.T4CTTIMsg.marshalTTCcode(T4CTTIMsg.java:223)
at oracle.jdbc.driver.T4CTTIrxd.marshal(T4CTTIrxd.java:194)
at oracle.jdbc.driver.T4C8Oall.marshalBinds(T4C8Oall.java:1493)
at oracle.jdbc.driver.T4C8Oall.marshalAll(T4C8Oall.java:973)
at oracle.jdbc.driver.T4C8Oall.marshal(T4C8Oall.java:422)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:199)
at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:796)
at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1031)
at oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe(T4CPreparedStatement.java:836)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1124)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3285)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3329)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1953)
at org.hibernate.loader.Loader.doQuery(Loader.java:802)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
at org.hibernate.loader.Loader.loadEntity(Loader.java:2037)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:86)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:76)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3293)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:496)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:477)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:227)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:285)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:152)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:1090)
at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:1038)
at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:630)
at org.hibernate.type.EntityType.resolve(EntityType.java:438)
at org.hibernate.type.ComponentType.resolve(ComponentType.java:617)
at org.hibernate.loader.Loader.extractKeysFromResultSet(Loader.java:722)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:606)
at org.hibernate.loader.Loader.doQuery(Loader.java:829)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
at org.hibernate.loader.Loader.loadEntity(Loader.java:2037)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:86)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:76)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3293)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:496)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:477)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:227)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:285)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:152)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:1090)
at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:1038)
at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:630)
at org.hibernate.type.EntityType.resolve(EntityType.java:438)
at org.hibernate.type.ComponentType.resolve(ComponentType.java:617)
at org.hibernate.loader.Loader.extractKeysFromResultSet(Loader.java:722)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:606)
at org.hibernate.loader.Loader.doQuery(Loader.java:829)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
at org.hibernate.loader.Loader.loadEntity(Loader.java:2037)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:86)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:76)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3293)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:496)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:477)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:227)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:285)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:152)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:1090)
at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:1038)
at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:630)
at org.hibernate.type.EntityType.resolve(EntityType.java:438)
at org.hibernate.type.ComponentType.resolve(ComponentType.java:617)
at org.hibernate.loader.Loader.extractKeysFromResultSet(Loader.java:722)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:606)
at org.hibernate.loader.Loader.doQuery(Loader.java:829)
我的课程是:
Users.java
@Entity
@Table(name = "USERS")
public class Users {
private Long user_id;
private Long niu;
private String nom;
private String mail;
private Set<UserContext> userContexts = new HashSet<UserContext>(0);
@OneToMany(fetch = FetchType.EAGER, mappedBy = "pk.user", cascade =
{CascadeType.ALL}, orphanRemoval=true)
public Set<UserContext> getUserContexts() {
return userContexts;
}
public void setUserContexts(Set<UserContext> userContexts) {
this.userContexts = userContexts;
}
}
Context.java
@Entity
@Table(name = "CONTEXT")
public class Context {
private Long id;
private String name;
private Area area;
private String code;
private Set<UserContext> userContexts = new HashSet<UserContext>(0);
@OneToMany(fetch = FetchType.EAGER, mappedBy = "pk.context", cascade = {CascadeType.ALL})
public Set<UserContext> getUserContexts() {
return userContexts;
}
}
UserContext.java
@Entity
@Table(name = "USER_CONTEXT")
@AssociationOverrides({
@AssociationOverride(name = "pk.user",
joinColumns = @JoinColumn(name = "USER_ID")),
@AssociationOverride(name = "pk.context",
joinColumns = @JoinColumn(name = "CTXT_ID")) })
public class UserContext implements Serializable{
private static final long serialVersionUID = 1L;
private UserContextID pk = new UserContextID();
private String admin;
@EmbeddedId
public UserContextID getPk() {
return pk;
}
@Transient
public Users getUser() {
return getPk().getUser();
}
public void setUser(Users user) {
getPk().setUser(user);
}
@Transient
public Context getContext() {
return getPk().getContext();
}
public void setContext(Context cntx) {
getPk().setContext(cntx);
}
public void setPk(UserContextID pk) {
this.pk = pk;
}
@Column(name = "ADMIN", unique = false, nullable = true, length = 1)
public String getAdmin(){
return admin;
}
public void setAdmin(String admin) {
this.admin = admin;
}
}
UserContextID.java
@Embeddable
public class UserContextID implements Serializable {
private static final long serialVersionUID = -9120607274421816301L;
private Users user;
private Context context;
@ManyToOne
public Users getUser() {
return user;
}
public void setUser(Users user) {
this.user = user;
}
@ManyToOne
public Context getContext() {
return context;
}
public void setContext(Context context) {
this.context = context;
}
}
有人知道会发生什么吗?正如我在User容器中创建refresh()时告诉你的那样,发生了StackOverFlowException。请帮助我!!