[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-6661) Parent-child self-referencing relationship via link table causes QuerySyntaxException:(table) is not mapped when retrieving previous revisions

Xi Zhang (JIRA) noreply at atlassian.com
Wed Jan 18 10:08:09 EST 2012


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-6661?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=45167#comment-45167 ] 

Xi Zhang commented on HHH-6661:
-------------------------------

I have the same db structure and problem as described.

As mentioned in other issue(https://hibernate.onjira.com/browse/HHH-5482), ENVERS audits such @ManyToOne in a separate {{JoinTable}} incorrectly.

I attached a snippet of HBM document which is generated by ENVERS-annotations for maintaining the ManyToOne relationship.

IMHO Hibernate-Core ignors the {{properties}}-Tag in HBM below, data for parent-side are not persisted in history table. 

Does ENVERS use the {{properties}}-construct in its HBM correctly? according to document of http://xdoclet.codehaus.org/HibernateTags#HibernateTags-hibernateproperties, it is just a logical grouping of properties.
 
{code}
<hibernate-mapping auto-import="false">
	<class entity-name="Tree_HSTRY" table="Tree_HSTRY">
		<composite-id name="treeId">
			<key-property insert="true" name="id" type="long" update="false">
				<column length="255" name="ID" precision="19" scale="2"/>
			</key-property>
			<key-many-to-one class="org.hibernate.envers.DefaultRevisionEntity" name="REV" type="integer">
				<column name="REV"/>
			</key-many-to-one>
		</composite-id>
		<property insert="true" name="REVTYPE" type="org.hibernate.envers.entities.RevisionTypeType" update="false"/>
		<property insert="true" name="name" type="string" update="false">
			<column length="255" name="NAME" precision="19" scale="2"/>
		</property>
		<join table="Tree_HIERARCHY_HSTRY">
			<key>
				<column length="255" name="CHILD_ID" precision="19" scale="2"/>
				<column name="REV"/>
			</key>
			<properties name="parent">
				<property insert="true" name="parent_id" type="long" update="false">
					<column length="255" name="PARENT_ID" precision="19" scale="2"/>
				</property>
			</properties>
		</join>
	</class>
</hibernate-mapping>
{code}


> Parent-child self-referencing relationship via link table causes QuerySyntaxException:(table) is not mapped when retrieving previous revisions
> ----------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: HHH-6661
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6661
>             Project: Hibernate ORM
>          Issue Type: Bug
>          Components: envers
>    Affects Versions: 3.6.7
>         Environment: Hibernate 3.6.7.Final, Oracle 11g DB (also reproduced with Derby 10.8.1.2), Spring 3.0.3
>            Reporter: Gerard Krupa
>         Attachments: gjkrupa_envers_problem.zip
>
>
> We have a parent-child relationship set up for an entity using a plain link table.  This is annotated with @JoinTable and @AuditJoinTable so there is no entity for the link table itself.  The definition looks something like this...
>  
> @Entity
> @Table(name = "BKG_BKCM_BKG_CMPT")
> @Audited
> public class BookingComponent implements Serializable {
> @ManyToOne(fetch = FetchType.LAZY, optional = true)
> @AuditJoinTable(name = "BKG_BKCMR_REL_AUD", inverseJoinColumns = { @JoinColumn(name = "BKCM_ID_PARENT", nullable = true, updatable = false) })
> @JoinTable(name = "BKG_BKCMR_REL", joinColumns = { @JoinColumn(name = "BKCM_ID_CHILD", nullable = true, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "BKCM_ID_PARENT", nullable = true, updatable = false) })
> private BookingComponent parent;
> @OneToMany(mappedBy = "parent")
> private List<BookingComponent> children;
> }
>  
> We've found two issues.  Firstly, when we try to retrieve a previous revision of these entities (they in turn are held in a collection in a container entity) using List<>.size() Envers seems to be constructing a JPQL query using the link table's table name which isn't valid JPQL resulting in the following exception:
> org.hibernate.hql.ast.QuerySyntaxException: BKG_BKCMR_REL_AUD is not mapped [select new list(ee, e) from BKG_BKCMR_REL_AUD ee, *package-name-omitted*.BookingComponent_AUD e where ee.originalId.BookingComponent_id = e.originalId.id and ee.originalId.children_id = :children_id and e.originalId.rev_id.id <= :revision and ee.originalId.rev_id.id <= :revision and ee.rev_type != :delrevisiontype and e.rev_type != :delrevisiontype and (e.REV_ID_END.id > :revision or e.REV_ID_END is null) and (ee.REV_ID_END.id > :revision or ee.REV_ID_END is null)]
>     at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:180)
>     at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:111)
>     at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:93)
>     at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:327)
>     at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3441)
>     at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:3325)
>     at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:733)
>     at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:584)
>     at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:301)
>     at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:244)
>     at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:254)
>     at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185)
>     at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
>     at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
>     at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
>     at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:124)
>     at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
>     at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)
>     at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1770)
>     at org.hibernate.envers.entities.mapper.relation.query.TwoEntityQueryGenerator.getQuery(TwoEntityQueryGenerator.java:128)
>     at org.hibernate.envers.entities.mapper.relation.lazy.initializor.AbstractCollectionInitializor.initialize(AbstractCollectionInitializor.java:62)
>     at org.hibernate.envers.entities.mapper.relation.lazy.proxy.CollectionProxy.checkInit(CollectionProxy.java:50)
>     at org.hibernate.envers.entities.mapper.relation.lazy.proxy.CollectionProxy.size(CollectionProxy.java:55)
>  
> We've also noticed that the audit entries for the link table have a null REV_ID_END despite there being multiple revisions.
> See attached gjkrupa_envers_problem.zip for a test case that demonstrates this issue.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list