2

我正在尝试从 4.0.1 升级到休眠 4.1.7.Final,但出现以下错误:

Failed to start service jboss.persistenceunit."****/********": org.jboss.msc.service.StartException in service jboss.persistenceunit."*****": Failed to start service
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1767) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_35]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_35]
at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_35] 

Caused by: javax.persistence.PersistenceException: [PersistenceUnit: myatrium_intranet] Unable to build EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:915)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:890)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:74)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.createContainerEntityManagerFactory(PersistenceUnitServiceImpl.java:162)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.start(PersistenceUnitServiceImpl.java:85)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
... 3 more
Caused by: org.hibernate.HibernateException: Could not locate table which owns column [id] referenced in order-by mapping
at org.hibernate.persister.entity.JoinedSubclassEntityPersister.determineTableNumberForColumn(JoinedSubclassEntityPersister.java:854)
at org.hibernate.persister.entity.AbstractEntityPersister.getTableAliasForColumn(AbstractEntityPersister.java:4865)
at org.hibernate.persister.collection.AbstractCollectionPersister$StandardOrderByAliasResolver.resolveTableAlias(AbstractCollectionPersister.java:1930)
at org.hibernate.sql.ordering.antlr.OrderByFragmentTranslator$StandardOrderByTranslationImpl.injectAliases(OrderByFragmentTranslator.java:106)
at org.hibernate.persister.collection.AbstractCollectionPersister.getSQLOrderByString(AbstractCollectionPersister.java:751)
at org.hibernate.loader.JoinWalker.orderBy(JoinWalker.java:910)
at org.hibernate.loader.JoinWalker.orderBy(JoinWalker.java:822)
at org.hibernate.loader.AbstractEntityJoinWalker.initStatementString(AbstractEntityJoinWalker.java:123)
at org.hibernate.loader.AbstractEntityJoinWalker.initStatementString(AbstractEntityJoinWalker.java:108)
at org.hibernate.loader.AbstractEntityJoinWalker.initAll(AbstractEntityJoinWalker.java:90)
at org.hibernate.loader.AbstractEntityJoinWalker.initAll(AbstractEntityJoinWalker.java:77)
at org.hibernate.loader.entity.CascadeEntityJoinWalker.<init>(CascadeEntityJoinWalker.java:51)
at org.hibernate.loader.entity.CascadeEntityLoader.<init>(CascadeEntityLoader.java:46)
at org.hibernate.persister.entity.AbstractEntityPersister.createLoaders(AbstractEntityPersister.java:3785)
at org.hibernate.persister.entity.AbstractEntityPersister.postInstantiate(AbstractEntityPersister.java:3722)
at org.hibernate.persister.entity.SingleTableEntityPersister.postInstantiate(SingleTableEntityPersister.java:1018)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:457)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1750)
at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:94)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:905)
... 9 more

我不知道休眠在说哪个表。有什么方法可以了解它吗?我还需要添加什么特别的东西才能让它工作吗?请注意,我的数据结构适用于 4.0.1。

任何帮助将非常感激。

更新:我已经打开了休眠的调试,我想知道如何找出哪个类导致了问题。有没有办法知道它来自哪个班级?只是提醒您,错误来自预加载查询,休眠在启动服务器之前执行。

提前致谢

4

1 回答 1

4

我已经弄清楚了最终发生这种情况的情况,并且很快将使用 hibernate 提交错误报告,并在我这样做时将其链接到此处。如果您有一个使用 JOINED 的继承策略的实体,并且您将父实体引用为另一个实体中的集合并向集合添加 o​​rder by,则会引发 OP 发布的错误。

例如:

@Entity
@Table(name = "Joined_Parent")
@Inheritance(strategy = InheritanceType.JOINED)
public class JoinedParent
{
    @Id
    @GeneratedValue
    @Column(name = "id")
    private Integer id;

    @ManyToOne(cascade = {CascadeType.ALL})
    @JoinColumn(name = "other_entity_id", nullable = false)
    private OtherEntity otherEntity;
}

@Entity
@Table(name = "Joined_Child")
@PrimaryKeyJoinColumn(name = "id")
public class JoinedChild
    extends JoinedParent
{
}

@Entity
@Table(name = "Other_Entity")
public class OtherEntity
{
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "otherEntity", orphanRemoval = true)
    @OrderBy("id ASC") // <-- this causes the error
    private List<JoinedParent> items = new ArrayList<JoinedParent>();
}

我不确定这是否仅在您将父级作为集合引用时才会发生,或者它是否也与子实体一起发生。我也不确定是否有双向关系与它有任何关系。我在这里提交了一个错误报告https://hibernate.onjira.com/browse/HHH-7630

于 2012-09-18T23:35:55.090 回答