[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-879?page=co...
]
James Olsen commented on HHH-879:
---------------------------------
WORKAROUND
I use extra 'query keys' (a term borrowed from a competing product) as shown
below.
This first mapping is the standard one. In my case it's protected, FetchType.LAZY and
ignores any data as I never use it to retrieve data directly. It's just metadata for
a query key so that I have transitive closure for these objects in a distributed system
but still have all the relationships defined for querying purposes. You could have this
first mapping as a proper mapping if you want.
@OneToMany(targetEntity = TradeOrderAuditImpl.class, fetch = FetchType.LAZY, mappedBy =
"tradeOrder")
protected Set<TradeOrderAudit> getTradeOrderAudits() {
return null;
}
protected void setTradeOrderAudits(Set<TradeOrderAudit> tradeOrderAudits) {
}
This second mapping is to the same entity. Again, it's just a query key. In this
case it also happens to have a constraint which uniquely identifies the target object
(making this suit a single purpose). This is completely optional, you could leave the
@Where off and use criteria to constrain in the normal way (making it as general purpose
as the standard mapping).
@OneToMany(targetEntity = TradeOrderAuditImpl.class, fetch = FetchType.LAZY, mappedBy =
"tradeOrder")
@Where(clause="ORDER_ACTION_EN = 6")
protected Set<TradeOrderAudit> getFillTradeOrderAudit() {
return null;
}
protected void setFillTradeOrderAudit(Set<TradeOrderAudit> tradeOrderAudits) {
}
Now I can refer to both 'tradeOrderAudits' and 'fillTradeOrderAudit' which
relate to the same table and use them in query restrictions and projections.
These query keys don't seem to affect performance too much. On merge hibernate thinks
the collections have simply been dereferenced and ignores them (no cascading).
I rely on these a lot (more for the transitive-closure-with-full-relationship-metadata
benefit) so it would actually be nice to have the notion of a 'query key' promoted
to a first class item rather than this hack. Perhaps equivalents of the existing
relationship annotations but with 'QK' prefixed and placed at the class level?
Enable joining the same association twice with Criteria
-------------------------------------------------------
Key: HHH-879
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-879
Project: Hibernate3
Issue Type: Improvement
Components: core
Reporter: Vladimir Bayanov
Make double joining the same association with Criteria.createCriteria possible. See:
http://forum.hibernate.org/viewtopic.php?t=931249
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira