我有一个主要和次要类用于存储保存时的错误。 错误可以是各种类型,主键是主类和错误类型。 这是我的类的映射:
我的小班:
@Entity
@Table(name = "foo")
public class FooEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
@Column(name = "id")
private Integer id;
@Column(name = "param1")
private String param1;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "id.foo", cascade = CascadeType.ALL)
List<FooErrorEntity> errors;
//getters&setters
}
我的错误类:
@Entity
@Table(name = "fooerror")
public class FooErrorEntity implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
private FooErrorId id;
@Column(name = "descripcion")
private String description;
//Getters&& setters
}
我的错误ID类:
@Embeddable
public class FooErrorId implements Serializable {
private static final long serialVersionUID = 1L;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "foo_id", nullable = false)
private FooEntity foo;
@Enumerated(EnumType.STRING)
@Column(name = "type")
private ErrorType type;
//getters&setters
}
在我的控制器中,我会检查错误并将其添加到列表中:
@RequestMapping(method = RequestMethod.POST) public final String saveFoo(@ModelAttribute(&#34; foo&#34;)FooEnntity foo){
//My checks... and add the errors
FooErrorEntity error1 = new FooErrorEntity();
error1.setDescription("Desc1");
FooErrorId errorId1 = new FooErrorId();
errorId1.setFoo(foo);
errorId1.setType(ErrorType.ERROR3);
error1.setId(errorId1);
foo.getErrors().add(error1);
fooService.save(foo);
return "view";
}
如果我正在编辑有错误的FooEntity,我会收到此错误:
Hibernate: select errors0_.foo_id as foo_id3_2_0_, errors0_.type as type1_2_0_, errors0_.foo_id as foo_id3_2_1_, errors0_.type as type1_2_1_, errors0_.descripcion as descripc2_2_1_ from fooerror errors0_ where errors0_.foo_id=? Hibernate: select fooentity0_.id as id1_1_1_, fooentity0_.param1 as param2_1_1_, errors1_.foo_id as foo_id3_2_3_, errors1_.type as type1_2_3_, errors1_.foo_id as foo_id3_2_0_, errors1_.type as type1_2_0_, errors1_.descripcion as descripc2_2_0_ from foo fooentity0_ left outer join fooerror errors1_ on fooentity0_.id=errors1_.foo_id where fooentity0_.id=? .... Hibernate: select fooentity0_.id as id1_1_1_, fooentity0_.param1 as param2_1_1_, errors1_.foo_id as foo_id3_2_3_, errors1_.type as type1_2_3_, errors1_.foo_id as foo_id3_2_0_, errors1_.type as type1_2_0_, errors1_.descripcion as descripc2_2_0_ from foo fooentity0_ left outer join fooerror errors1_ on fooentity0_.id=errors1_.foo_id where fooentity0_.id=? Hibernate: select fooentity0_.id as id1_1_1_, fooentity0_.param1 as param2_1_1_, errors1_.foo_id as foo_id3_2_3_, errors1_.type as type1_2_3_, errors1_.foo_id as foo_id3_2_0_, errors1_.type as type1_2_0_, errors1_.descripcion as descripc2_2_0_ from foo fooentity0_ left outer join fooerror errors1_ on fooentity0_.id=errors1_.foo_id where fooentity0_.id=? Hibernate: select fooentity0_.id as id1_1_1_, fooentity0_.param1 as param2_1_1_, errors1_.foo_id as foo_id3_2_3_, errors1_.type as type1_2_3_, errors1_.foo_id as foo_id3_2_0_, errors1_.type as type1_2_0_, errors1_.descripcion as descripc2_2_0_ from foo fooentity0_ left outer join fooerror errors1_ on fooentity0_.id=errors1_.foo_id where fooentity0_.id=? mar 01, 2016 9:15:57 PM org.apache.catalina.core.StandardWrapperValve invoke GRAVE: El Servlet.service() para el servlet [dispatcher] en el contexto con ruta [/springMVC] lanzó la excepción [Handler processing failed; nested exception is java.lang.StackOverflowError] con causa raíz java.lang.StackOverflowError at com.mysql.jdbc.Util.handleNewInstance(Util.java:428) at com.mysql.jdbc.PreparedStatement.getInstance(PreparedStatement.java:834) at com.mysql.jdbc.ConnectionImpl.clientPrepareStatement(ConnectionImpl.java:1573) at com.mysql.jdbc.ConnectionImpl.prepareStatement(ConnectionImpl.java:4591) at com.mysql.jdbc.ConnectionImpl.prepareStatement(ConnectionImpl.java:4489)
at org.apache.commons.dbcp.DelegatingConnection.prepareStatement(DelegatingConnection.java:281) at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.prepareStatement(PoolingDataSource.java:313) at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$5.doPrepare(StatementPreparerImpl.java:146) at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:172) at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatement(StatementPreparerImpl.java:148) at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1928) at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1897) at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1875) at org.hibernate.loader.Loader.doQuery(Loader.java:919) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:336) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:306) at org.hibernate.loader.Loader.loadEntity(Loader.java:2198) at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:60) at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:50) at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3956) at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:508) at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:478) at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:219) at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:278) at org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:121) at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:89) at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1129) at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1022) at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:632) at org.hibernate.type.EntityType.resolve(EntityType.java:424) at org.hibernate.type.ComponentType.resolve(ComponentType.java:687) at org.hibernate.loader.Loader.extractKeysFromResultSet(Loader.java:848) at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:714) at org.hibernate.loader.Loader.processResultSet(Loader.java:972) at org.hibernate.loader.Loader.doQuery(Loader.java:930) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:336) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:306) at org.hibernate.loader.Loader.loadEntity(Loader.java:2198) at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:60) at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:50) at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3956) at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:508) at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:478) at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:219) at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:278) at org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:121) at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:89) at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1129)
at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1022) at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:632) at org.hibernate.type.EntityType.resolve(EntityType.java:424) at org.hibernate.type.ComponentType.resolve(ComponentType.java:687) at org.hibernate.loader.Loader.extractKeysFromResultSet(Loader.java:848) at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:714) at org.hibernate.loader.Loader.processResultSet(Loader.java:972) at org.hibernate.loader.Loader.doQuery(Loader.java:930) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:336) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:306) at org.hibernate.loader.Loader.loadEntity(Loader.java:2198) at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:60) at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:50) at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3956) at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:508) at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:478) at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:219) at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:278) at org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:121) at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:89) at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1129) at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1022) at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:632) at org.hibernate.type.EntityType.resolve(EntityType.java:424) at org.hibernate.type.ComponentType.resolve(ComponentType.java:687) at org.hibernate.loader.Loader.extractKeysFromResultSet(Loader.java:848) at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:714) at org.hibernate.loader.Loader.processResultSet(Loader.java:972) at org.hibernate.loader.Loader.doQuery(Loader.java:930) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:336) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:306) at org.hibernate.loader.Loader.loadEntity(Loader.java:2198) at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:60) at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:50) at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3956) at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:508) at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:478) at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:219) at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:278) at org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:121) at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:89) at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1129)
at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1022) at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:632) at org.hibernate.type.EntityType.resolve(EntityType.java:424) at org.hibernate.type.ComponentType.resolve(ComponentType.java:687) at org.hibernate.loader.Loader.extractKeysFromResultSet(Loader.java:848) at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:714) at org.hibernate.loader.Loader.processResultSet(Loader.java:972) at org.hibernate.loader.Loader.doQuery(Loader.java:930) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:336) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:306) at org.hibernate.loader.Loader.loadEntity(Loader.java:2198) at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:60) at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:50) at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3956) at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:508) at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:478) at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:219) at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:278) at org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:121) at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:89) at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1129) at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1022) at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:632) at org.hibernate.type.EntityType.resolve(EntityType.java:424) at org.hibernate.type.ComponentType.resolve(ComponentType.java:687) at org.hibernate.loader.Loader.extractKeysFromResultSet(Loader.java:848) at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:714) at org.hibernate.loader.Loader.processResultSet(Loader.java:972) at org.hibernate.loader.Loader.doQuery(Loader.java:930) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:336) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:306) at org.hibernate.loader.Loader.loadEntity(Loader.java:2198) at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:60) at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:50) at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3956) at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:508) at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:478) at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:219) at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:278) at org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:121) at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:89) at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1129) at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1022) at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:632) at org.hibernate.type.EntityType.resolve(EntityType.java:424) at org.hibernate.type.ComponentType.resolve(ComponentType.java:687) at org.hibernate.loader.Loader.extractKeysFromResultSet(Loader.java:848) at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:714) at org.hibernate.loader.Loader.processResultSet(Loader.java:972) at org.hibernate.loader.Loader.doQuery(Loader.java:930) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:336) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:306) at org.hibernate.loader.Loader.loadEntity(Loader.java:2198) at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:60) at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:50) at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3956) at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:508) at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:478) at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:219) at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:278) at org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:121) at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:89) at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1129) at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1022) at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:632) at org.hibernate.type.EntityType.resolve(EntityType.java:424) at org.hibernate.type.ComponentType.resolve(ComponentType.java:687) at org.hibernate.loader.Loader.extractKeysFromResultSet(Loader.java:848) at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:714) at org.hibernate.loader.Loader.processResultSet(Loader.java:972) at org.hibernate.loader.Loader.doQuery(Loader.java:930) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:336) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:306) at org.hibernate.loader.Loader.loadEntity(Loader.java:2198) at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:60) at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:50) at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3956) at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:508) at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:478) at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:219) at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:278) at org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:121) at
> org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:89)
at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1129) at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1022) at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:632) at org.hibernate.type.EntityType.resolve(EntityType.java:424) at org.hibernate.type.ComponentType.resolve(ComponentType.java:687) at org.hibernate.loader.Loader.extractKeysFromResultSet(Loader.java:848) at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:714) at org.hibernate.loader.Loader.processResultSet(Loader.java:972) at org.hibernate.loader.Loader.doQuery(Loader.java:930) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:336) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:306) at org.hibernate.loader.Loader.loadEntity(Loader.java:2198) at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:60) at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:50) at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3956) at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:508) at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:478) at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:219) at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:278) at org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:121) at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:89) at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1129) at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1022) at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:632) at org.hibernate.type.EntityType.resolve(EntityType.java:424) at org.hibernate.type.ComponentType.resolve(ComponentType.java:687) at org.hibernate.loader.Loader.extractKeysFromResultSet(Loader.java:848) at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:714) at org.hibernate.loader.Loader.processResultSet(Loader.java:972) at org.hibernate.loader.Loader.doQuery(Loader.java:930) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:336) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:306) at org.hibernate.loader.Loader.loadEntity(Loader.java:2198) at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:60) at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:50) at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3956) at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:508) at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:478) at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:219) at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:278) at org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:121) at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:89) at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1129) at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1022) at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:632) at org.hibernate.type.EntityType.resolve(EntityType.java:424) at org.hibernate.type.ComponentType.resolve(ComponentType.java:687) at org.hibernate.loader.Loader.extractKeysFromResultSet(Loader.java:848) at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:714) at org.hibernate.loader.Loader.processResultSet(Loader.java:972) at org.hibernate.loader.Loader.doQuery(Loader.java:930) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:336) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:306) at org.hibernate.loader.Loader.loadEntity(Loader.java:2198) at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:60) at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:50) at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3956) at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:508) at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:478) at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:219) at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:278) at org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:121) at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:89) at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1129) at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1022) at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:632) at org.hibernate.type.EntityType.resolve(EntityType.java:424) at org.hibernate.type.ComponentType.resolve(ComponentType.java:687) at org.hibernate.loader.Loader.extractKeysFromResultSet(Loader.java:848) at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:714) at org.hibernate.loader.Loader.processResultSet(Loader.java:972) at org.hibernate.loader.Loader.doQuery(Loader.java:930) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:336) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:306) at org.hibernate.loader.Loader.loadEntity(Loader.java:2198) at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:60) at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:50) at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3956) at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:508) at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:478) at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:219) at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:278) at org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:121) at
> org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:89)
at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1129) at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1022) at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:632) at org.hibernate.type.EntityType.resolve(EntityType.java:424) at org.hibernate.type.ComponentType.resolve(ComponentType.java:687) at org.hibernate.loader.Loader.extractKeysFromResultSet(Loader.java:848) at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:714) at org.hibernate.loader.Loader.processResultSet(Loader.java:972) at org.hibernate.loader.Loader.doQuery(Loader.java:930) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:336) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:306) at org.hibernate.loader.Loader.loadEntity(Loader.java:2198) at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:60) at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:50) at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3956) at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:508) at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:478) at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:219) at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:278) at org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:121) at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:89) at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1129) at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1022) at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:632) at org.hibernate.type.EntityType.resolve(EntityType.java:424) at org.hibernate.type.ComponentType.resolve(ComponentType.java:687) at org.hibernate.loader.Loader.extractKeysFromResultSet(Loader.java:848) at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:714) at org.hibernate.loader.Loader.processResultSet(Loader.java:972) at org.hibernate.loader.Loader.doQuery(Loader.java:930) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:336) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:306) at org.hibernate.loader.Loader.loadEntity(Loader.java:2198) at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:60)
并且日志继续...我得到无限选择foo表
答案 0 :(得分:4)
你有一个派生身份。
FooEntity.errors
应该&#34;映射为&#34; foo
:
public class FooEntity implements Serializable {
...
@OneToMany(fetch = FetchType.LAZY, mappedBy = "foo", cascade = CascadeType.ALL)
List<FooErrorEntity> errors;
...
}
FooErrorEntity
关系foo
应移出@EmbeddedId
并移至@Entity
本身,并应指定@MapsId
:
@Entity
@Table(name = "fooerror")
public class FooErrorEntity implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
private FooErrorId id;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "foo_id", nullable = false)
@MapsId("fooId") // maps fooId attribute of the embedded id
private FooEntity foo;
@Column(name = "descripcion")
private String description;
...
}
FooErrorId
&#39; foo
应替换为fooId
,其类型对应FooEntity
的主键类型:
@Embeddable
public class FooErrorId implements Serializable {
private static final long serialVersionUID = 1L;
private Integer fooId; // type corresponds to FooEntity's id
@Enumerated(EnumType.STRING)
@Column(name = "type")
private ErrorType type;
...
}
JPA 2.1规范第2.4.1节讨论了派生身份。
答案 1 :(得分:-1)
对我来说看起来像一个无限循环--FooEntity有一个FooErrorEntity列表,其中有一个FooErrorId,它有一个FooEntry。这已经是循环依赖。