我有一个主要和次要的类,用于保存时的错误。
错误可以有多种类型,主键是错误的主要类别和类型。
这是我的课程的映射:

我的小学班:

@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(方法= RequestMethod.POST)
公共最终字符串saveFoo(@ModelAttribute(“ foo”)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表

最佳答案

您具有派生身份。

FooEntity.errors应该被“ 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;

    ...
}


并且FooErrorIdfoo应该替换为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节中讨论了派生身份。

07-26 04:53