[Hibernate-JIRA] Commented: (HHH-952) Patch to allow subqueries with joins using Criteria API and Subqueries with DetachedCriteria
by Don Mitchell (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-952?page=co... ]
Don Mitchell commented on HHH-952:
----------------------------------
Matthias,
Can you post the code that generated the SQL you posted?
Thanks,
Don
> Patch to allow subqueries with joins using Criteria API and Subqueries with DetachedCriteria
> --------------------------------------------------------------------------------------------
>
> Key: HHH-952
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-952
> Project: Hibernate3
> Issue Type: Patch
> Components: core
> Affects Versions: 3.1 beta 1, 3.1 beta 2
> Environment: 3.1beta1 with MS SQL 2000 via jTDS
> Reporter: John
> Priority: Critical
> Attachments: subquery-patch-311.txt, subquery-patch-313.txt, subquery-patch-31beta3.txt, subquery-patch.txt, subquery-patch.txt, SubqueryExpression.java
>
>
> The existing code in SubqueryExpression.java constructed a select statement but did not have any provisions for creating joins. Therefore, it was not possible using the criteria API to create an exists subselect that had a join, even though running the source DetachedCriteria alone works perfectly.
> For example, if this is the goal:
> select * from foo f
> where exists (select id from bar b join other o on b.o_id = o.id where o.prop = '123' and b.foo_id = f.id)
> One might try something like this:
> Criteria crit = session.createCriteria(Foo.class, fooAlias);
> DetachedCriteria barCrit = DetachedCriteria.forClass(Bar.class, barAlias);
> DetachedCriteria otherCrit = barCrit.createCriteria(Bar.OTHER_JOIN);
> otherCrit.add( Restrictions.eq(Other.PROP, "123") );
> barCrit.add( Restrictions.eqProperty( -- props to join to foo here --) );
> barCrit.setProjection( Projections.id() );
> crit.add( Subqueries.exists(barCrit) );
> However, the existing code generates something like the following, which gets an error with an unknown alias 'o':
> select * from foo f
> where exists (select id from bar b where o.prop = '123' and b.foo_id = f.id)
> This is also described here (at the end): http://forum.hibernate.org/viewtopic.php?t=942488
> The patch to SubqueryExpression.java fixes this to included the joins necessary for the filtering. This code was modeled (copied) off of code from CriteriaLoader. For me this works perfectly, but I don't understand the internals of this stuff enough to say how robust it is. Also included is a patch to the test case to enable testing of this, which was present but commented out. I did not change the contents of the test, which currently only attempts a joined subquery. This used to fail with an error, but now it works. The test does not check the results at all. (Inconsequential to the patch - Enrollment has two Ls.)
> -----side notes
> The patch file also has two other patches. The first increases the delay in BulkManipulationTest because I was getting inconsistent test results. I think that the precision on the version timestamp is not enough for 300 milliseconds delay to be enough to guarantee the test results. Also, in build.xml, there was a line that was meant to exclude the performance tests, but there was no **/*, on *, so they actually were not excluded. I changed this so the tests would complete in a reasonable amount of time. However, there is one other issue with testing that I worked around manually. After each test run, two databases (Users and Email) were left in the database. If I did not manually delete these then the number of failures on the next test run was different. This was really confusing until I figured it out because I was trying to make sure all the other testcases still passed with my patch, but even without the patch I was getting different results.
--
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
17 years, 7 months
[Hibernate-JIRA] Commented: (HHH-1829) Allow join on any property using property-ref
by Graham Zabel (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1829?page=c... ]
Graham Zabel commented on HHH-1829:
-----------------------------------
any news on a fix for this? I don't see it fixed in 3.2.3 or 3.2.4. thanks.
> Allow join on any property using property-ref
> ---------------------------------------------
>
> Key: HHH-1829
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1829
> Project: Hibernate3
> Issue Type: New Feature
> Components: metamodel
> Affects Versions: 3.2.0 cr1, 3.2.0.cr2
> Reporter: Maarten Winkels
> Assignee: Steve Ebersole
> Attachments: AbstractJoinTest.java, HHH-1829-mwinkels.patch, hhh-1829.patch, JoinNoPropertyRefTest.java, JoinPropertyRefTest.java, Person.hbm.xml, Person.java, PersonNoPropertyRef.hbm.xml
>
>
> Currently joining tables for one class (uing the <join...> tag) is only supported for the id property. The property-ref is allowed on the <key..> tag inside the <join..> tag, but this is ignored.
--
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
17 years, 7 months
[Hibernate-JIRA] Commented: (HHH-952) Patch to allow subqueries with joins using Criteria API and Subqueries with DetachedCriteria
by Matthias Bayer (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-952?page=co... ]
Matthias Bayer commented on HHH-952:
------------------------------------
I tested the patch with v313 and not all seems to be OK.
select
distinct this_.d as y0_
from
mytable this_
where
(
exists (
select
this_.d as y0_
from
--not correct! The alias of the subquery should be 'this__'. In this special case the patch does not work.
--in SubqueryExpression.java Hibernate Version 3.1.3 and single detached criteria query the alias is 'this__',
mytable this_
where
this_.d=this_.d
and (
this_.a in (
?
)
and this_.b in (
?
)
and this_.c between ? and ?
)
)
> Patch to allow subqueries with joins using Criteria API and Subqueries with DetachedCriteria
> --------------------------------------------------------------------------------------------
>
> Key: HHH-952
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-952
> Project: Hibernate3
> Issue Type: Patch
> Components: core
> Affects Versions: 3.1 beta 1, 3.1 beta 2
> Environment: 3.1beta1 with MS SQL 2000 via jTDS
> Reporter: John
> Priority: Critical
> Attachments: subquery-patch-311.txt, subquery-patch-313.txt, subquery-patch-31beta3.txt, subquery-patch.txt, subquery-patch.txt, SubqueryExpression.java
>
>
> The existing code in SubqueryExpression.java constructed a select statement but did not have any provisions for creating joins. Therefore, it was not possible using the criteria API to create an exists subselect that had a join, even though running the source DetachedCriteria alone works perfectly.
> For example, if this is the goal:
> select * from foo f
> where exists (select id from bar b join other o on b.o_id = o.id where o.prop = '123' and b.foo_id = f.id)
> One might try something like this:
> Criteria crit = session.createCriteria(Foo.class, fooAlias);
> DetachedCriteria barCrit = DetachedCriteria.forClass(Bar.class, barAlias);
> DetachedCriteria otherCrit = barCrit.createCriteria(Bar.OTHER_JOIN);
> otherCrit.add( Restrictions.eq(Other.PROP, "123") );
> barCrit.add( Restrictions.eqProperty( -- props to join to foo here --) );
> barCrit.setProjection( Projections.id() );
> crit.add( Subqueries.exists(barCrit) );
> However, the existing code generates something like the following, which gets an error with an unknown alias 'o':
> select * from foo f
> where exists (select id from bar b where o.prop = '123' and b.foo_id = f.id)
> This is also described here (at the end): http://forum.hibernate.org/viewtopic.php?t=942488
> The patch to SubqueryExpression.java fixes this to included the joins necessary for the filtering. This code was modeled (copied) off of code from CriteriaLoader. For me this works perfectly, but I don't understand the internals of this stuff enough to say how robust it is. Also included is a patch to the test case to enable testing of this, which was present but commented out. I did not change the contents of the test, which currently only attempts a joined subquery. This used to fail with an error, but now it works. The test does not check the results at all. (Inconsequential to the patch - Enrollment has two Ls.)
> -----side notes
> The patch file also has two other patches. The first increases the delay in BulkManipulationTest because I was getting inconsistent test results. I think that the precision on the version timestamp is not enough for 300 milliseconds delay to be enough to guarantee the test results. Also, in build.xml, there was a line that was meant to exclude the performance tests, but there was no **/*, on *, so they actually were not excluded. I changed this so the tests would complete in a reasonable amount of time. However, there is one other issue with testing that I worked around manually. After each test run, two databases (Users and Email) were left in the database. If I did not manually delete these then the number of failures on the next test run was different. This was really confusing until I figured it out because I was trying to make sure all the other testcases still passed with my patch, but even without the patch I was getting different results.
--
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
17 years, 7 months
[Hibernate-JIRA] Created: (HHH-2316) org.hibernate.cache.CacheKey.equals() can cause PropertyAccessException to be thrown
by Joel Caplin (JIRA)
org.hibernate.cache.CacheKey.equals() can cause PropertyAccessException to be thrown
------------------------------------------------------------------------------------
Key: HHH-2316
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2316
Project: Hibernate3
Type: Bug
Components: core
Versions: 3.2.1
Environment: Windows XP / Sybase 12.5 / Java 1.5.0_09 / ehcache 1.2.4
Reporter: Joel Caplin
Priority: Critical
org.hibernate.cache.CacheKey.equals() uses lazy evaluation in its return clause: it first calls type.isEqual() and, if true, then calls entityOrRoleName.equals().
I am having difficulty reproducing this bug in the form of a test case owing to the complexity of our model and the large amount of data in question-- however, in certain circumstances, where the entityOrRoleName's are NOT equal, calling type.isEqual() yields a PropertyAccessException.
When this bug manifests itself (a PropertyAccessException is thrown), it causes ALL future Hibernate requests to throw a similar exception, thus rendering our service unusable.
This is fixed when the lazy evaluation is done the other way around: call entityOrRoleName.equals() prior to type.isEqual() - cheap string comparision vs an expensive call which has a large call tree under it.
--
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
17 years, 7 months
[Hibernate-JIRA] Created: (HHH-2336) UserCollectionType: add support for ParameterizedTypes and typedef'ed types to the collection-type attribute for a collection mapping
by Holger Brands (JIRA)
UserCollectionType: add support for ParameterizedTypes and typedef'ed types to the collection-type attribute for a collection mapping
-------------------------------------------------------------------------------------------------------------------------------------
Key: HHH-2336
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2336
Project: Hibernate3
Type: Improvement
Components: core
Versions: 3.2.1
Environment: Hibernate 3.2.1, independent of database platform
Reporter: Holger Brands
Attachments: usercollectionwithparameters.zip
Currently, it's required to specify a class name as value for the collection-type attribute of a collection mapping.
Therefore you can't use a typedef'ed type as collection-type and consequently you can't pass parameters to a custom collection type.
Please enhance the support for custom collection types such that you can do something like this:
<typedef name="MyEventListType" class="ca.odell.glazedlists.hibernate.EventListType">
<param name="category">Test</param>
</typedef>
<class name="User" table="`USERS`">
<id name="userName" column="USERNAME"/>
<!-- mapping a value collection -->
<list name="nickNames" table="USER_NICKNAMES"
collection-type="MyEventListType">
<key column="USER_ID"/>
<list-index column="DISPLAY_ORDER"/>
<element column="NAME" type="string" length="50"/>
</list>
</class>
Currently this mapping fails with this exception:
org.hibernate.MappingException: user colllection type class not found: MyEventListType
at org.hibernate.type.TypeFactory.customCollection(TypeFactory.java:267)
at org.hibernate.mapping.Collection.getCollectionType(Collection.java:348)
at org.hibernate.mapping.Collection.getType(Collection.java:340)
at org.hibernate.tuple.PropertyFactory.buildStandardProperty(PropertyFactory.java:120)
at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:163)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:425)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:109)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:226)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1291)
at ca.odell.glazedlists.hibernate.AbstractHibernateTestCase.buildSessionFactory(AbstractHibernateTestCase.java:133)
at ca.odell.glazedlists.hibernate.AbstractHibernateTestCase.setUp(AbstractHibernateTestCase.java:167)
at junit.framework.TestCase.runBare(TestCase.java:125)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: java.lang.ClassNotFoundException: MyEventListType
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:164)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:100)
at org.hibernate.type.TypeFactory.customCollection(TypeFactory.java:264)
... 24 more
Also see the coresponding forum entry for details:
http://forum.hibernate.org/viewtopic.php?t=969043
Attached is a test case that demonstrates this problem.
It's a modified copy of the existing "usercollection" test case in the Hibernate 3.2.1 distribution.
Just copy the directory into your org.hibernate.test directory and include it in your testsuite.
As I'm not familiar enough with the internals of Hibernate, I have no patch at hand, sorry.
Resolving this issue would enhance mapping flexibility for custom collection types because you
would be able to pass parameters as it's possible right now for UserTypes and CompositeUserTypes.
--
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
17 years, 7 months
[Hibernate-JIRA] Created: (HHH-2363) Hibernate is returning zero for the ID of a persistent object
by Archie Cobbs (JIRA)
Hibernate is returning zero for the ID of a persistent object
-------------------------------------------------------------
Key: HHH-2363
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2363
Project: Hibernate3
Type: Bug
Components: core
Versions: 3.2.0.ga
Environment: Hibernate 3.2.1 GA running on SuSE Linux
MySQL 4.1.13
java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing)
Reporter: Archie Cobbs
I have two classes, {{Patient}} and {{Room}}, where {{Patient}} has a FK many-to-one reference to {{Room}}, representing a room assignment.
Both classes use a Java {{long}} field named "id" as their identifier.
When I create a Session and find a Patient with a room assignment, the Patient's identifier is correct but the Room's identifier, when accessed via {{patient.getAssignedRoom().getId()}}, is ZERO. However, in the database the value is one and {{session.getIdentifier(patient.getAssignedRoom())}} also returns one, in contradiction.
A simple reproducible test case will be attached. Instructions:
# Edit {{doit.sh}} and set {{HIBERNATE_DIR}} to point to an unpacked {{hibernate-3.2.0.ga.tar.gz}} directory
# Set {{MYSQL_CONNECTOR_JAVA}} to point to {{myslq-connector-java.jar}}
# Set {{DATABASE_USERNAME}} and {{DATABASE_PASSWORD}} if needed
# Run {{doit.sh}}.
The output I get at the end is this:
{noformat}
2037 [main] INFO org.hibernate.cache.StandardQueryCache - starting query cache at region: org.hibernate.cache.StandardQueryCache
Hibernate: select this_.id as id0_0_, this_.assignedRoom as assigned2_0_0_, this_.name as name0_0_, this_.medicalRecordNumber as medicalR4_0_0_ from Patient this_ where this_.medicalRecordNumber=?
Hibernate: select room0_.id as id1_0_, room0_.name as name1_0_ from Room room0_ where room0_.id=?
2195 [main] INFO Main - patient=Patient[Fred Example] patient.assignedRoom=Room[Room 101]
2196 [main] INFO Main - patient.id=1
2196 [main] INFO Main - patient.assignedRoom.id=0
2196 [main] ERROR Main - WTF? ID OF ROOM IS ZERO!
2196 [main] INFO Main - patient.assignedRoom.id=1
{noformat}
Note the line {{patient.assignedRoom.id=0}} ... see the corresponding code in {{Main.java}}.
--
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
17 years, 7 months