[Hibernate-JIRA] Created: (HHH-2545) Query cache dosen't work with queries that return Collections
by Jacek halat (JIRA)
Query cache dosen't work with queries that return Collections
-------------------------------------------------------------
Key: HHH-2545
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2545
Project: Hibernate3
Issue Type: Bug
Components: core
Affects Versions: 3.2.3
Environment: Windows XP, jdk1.5.0_06
Reporter: Jacek halat
Priority: Critical
Attachments: QueryCacheBag.zip
If :
* second level cache is enabled
* query cache is enabled
* query return collection of objects
first query execution return collection of objects, but second, third etc, call returns.... Collection with null element (collection size is corect, but collection contains onlu null elements instead of objects).
I do some investigation and found, that if query cache is enabled, StandardQueryCache.put() method is caled. This method store cachable object in queryCache. Cachable is List with timestamp as first element and disassembled Entities as rest elements.
If List contains only 1 element this line is called:
if ( returnTypes.length==1 ) {
cacheable.add( returnTypes[0].disassemble( result.get(i), session, null ) );
}
else {
cacheable.add( TypeFactory.disassemble( (Object[]) result.get(i), returnTypes, null, session, null ) );
}
if query returns collection, CollectionType.disassemble() is called, this methods looks like:
public Serializable disassemble(Object value, SessionImplementor session, Object owner)
throws HibernateException {
//remember the uk value
//This solution would allow us to eliminate the owner arg to disassemble(), but
//what if the collection was null, and then later had elements added? seems unsafe
//session.getPersistenceContext().getCollectionEntry( (PersistentCollection) value ).getKey();
final Serializable key = getKeyOfOwner(owner, session);
if (key==null) {
return null;
}
else {
return getPersister(session)
.getKeyType()
.disassemble( key, session, owner );
}
}
This method is called with owner=null, and value=first element from collection.
IF cource because owner==null getKeyOfOwner returns null and null is stored in queryCache!!!!!!!!!!! (and no warning or error is logged or exception is thrown), so user can think, that query is corrcectly cached.
Now when query is executed second time, cached collection is returned, but it contains only null as value!!!!!
JUnit test included (QueryCacheBagTest)
For me this is critical bug, because it's impossible to work with qached query in clustered environment, so system performance is now very, very low.
I hope that this issue wil be resolved as soon possible.
--
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, 8 months
[Hibernate-JIRA] Updated: (HHH-817) using projections is causing SQL query error on oracle (ORA-00904 error)
by Milosz Tylenda (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-817?page=co... ]
Milosz Tylenda updated HHH-817:
-------------------------------
Attachment: HHH-817.patch
The patch is against the current 3.2 snapshot. It makes expressions in WHERE clause use column names instead of aliases.
Michal, sorry for the delay ;)
> using projections is causing SQL query error on oracle (ORA-00904 error)
> ------------------------------------------------------------------------
>
> Key: HHH-817
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-817
> Project: Hibernate3
> Issue Type: Bug
> Affects Versions: 3.0.5
> Environment: Oracle 9.2.0.6, Hibernate 3.0.5, Spring Framework 1.2.2 based application working on Jakarta Tomcat 5.0.28
> Reporter: Michal Jastak
> Priority: Minor
> Attachments: HHH-817.patch
>
>
> following java code:
> protected Entity loadEntityLightweight(Serializable entityId) throws DataAccessException {
> Criteria criteria = getSession().createCriteria(Entity.class);
> ProjectionList projectionList = Projections.projectionList();
> projectionList.add(Property.forName(BaseEntity.PROP_ID), BaseEntity.PROP_ID);
> projectionList.add(Property.forName(BaseEntity.PROP_TYPE), BaseEntity.PROP_TYPE);
> criteria.setProjection(projectionList);
> criteria.add(Restrictions.eq(BaseEntity.PROP_ID, entityId));
> criteria.setResultTransformer(new AliasToBeanResultTransformer(Entity.class));
> return (Entity) criteria.uniqueResult();
> }
> generates following SQL query:
> select this_.id as y0_, this_.type as y1_ from entities this_ left outer join facilities this_1_ on this_.id=this_1_.id left outer join users this_2_ on this_.id=this_2_.id left outer join addresses address2_ on this_.address_id=address2_.id left outer join entities entity3_ on this_2_.employer_id=entity3_.id left outer join facilities entity3_1_ on entity3_.id=entity3_1_.id left outer join users entity3_2_ on entity3_.id=entity3_2_.id where y0_=?
> y0_ = ? expression in where clause is causing a 904 error on Oracle 9:
> ORA-00904: "Y0_": invalid identifier
> hibernate dialect: org.hibernate.dialect.Oracle9Dialect
> mapping for Entity class:
> <?xml version="1.0"?>
> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
> "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
> <hibernate-mapping default-lazy="false" default-cascade="save-update">
>
> <class name="Entity" table="entities" mutable="true">
> <id name="id" type="java.lang.Long" unsaved-value="null">
> <generator class="sequence">
> <param name="sequence">entities_id_seq</param>
> </generator>
> </id>
> <many-to-one name="address" class="Address" column="address_id" />
> ...
> <!--
> - Facilities
> -->
> <joined-subclass name="Facility" table="facilities">
> <key column="id" />
> ...
> <set name="users" inverse="true" lazy="true">
> <key column="facility_id" />
> <one-to-many class="User" />
> </set>
> </joined-subclass>
> <!--
> - Users
> -->
> <joined-subclass name="User" table="users" dynamic-insert="true" dynamic-update="true">
> <key column="id" />
> <many-to-one name="employer" class="Entity" column="employer_id" cascade="none" />
> ...
> <set name="userAuthorities" inverse="true" cascade="all-delete-orphan">
> <key column="user_id" />
> <one-to-many class="Authority" />
> </set>
> </joined-subclass>
> </class>
> </hibernate-mapping>
--
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, 8 months
[Hibernate-JIRA] Commented: (HHH-1369) Restrictions.eq In Criteria Not matching a property of type java.lang.Class
by David CLEMENT (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1369?page=c... ]
David CLEMENT commented on HHH-1369:
------------------------------------
Class within criteria doesn't work since Queryable.getDiscriminatorSQLValue() returns a quotted value.
I had to use a workaround:
Queryable q =SessionFactoryHelper.findQueryableUsingImports((SessionFactoryImplementor) HibernateUtil.getSessionFactory(), objectClass.getName() );
String value = q.getDiscriminatorSQLValue().replaceAll("'", "");
c.add(Restrictions.eq("class", value));
> Restrictions.eq In Criteria Not matching a property of type java.lang.Class
> ---------------------------------------------------------------------------
>
> Key: HHH-1369
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1369
> Project: Hibernate3
> Issue Type: Bug
> Components: query-criteria
> Affects Versions: 3.1
> Environment: HB 3.1, Hibernate annotations 3.1-beta-7, Postgres 8.0.3
> Reporter: Matt Todd
> Attachments: criteriaclass.zip
>
>
> When using criteria query to get an entity using the following method:
> session.createCriteria(Vocabulary.class).add(Restrictions.eq("klass", MethodOfContact.class)).uniqueResult()
> No results are returned. Using an alternative method:
> session.createCriteria(Vocabulary.class).add(Restrictions.in("klass", new Object[] {MethodOfContact.class})).uniqueResult()
> returns the correct result.
> The annotations on the mapped class are:
> @Column(unique=true, nullable = false)
> private Class klass;
> The error is possibly comming from here looking at the debug:
> 15:50:55,479 DEBUG SQL:346 - /* criteria query */ select this_.id as id1_1_, this_.default_value as default5_1_1_, this_.name as name1_1_, this_.klass as klass1_1_, this_.type as type1_1_, vocabulary2_.id as id0_0_, vocabulary2_.available as available0_0_, vocabulary2_.value as value0_0_, vocabulary2_.type as type0_0_ from vocabulary this_ left outer join vocabulary_value vocabulary2_ on this_.default_value=vocabulary2_.id where this_.klass=?
> Hibernate: /* criteria query */ select this_.id as id1_1_, this_.default_value as default5_1_1_, this_.name as name1_1_, this_.klass as klass1_1_, this_.type as type1_1_, vocabulary2_.id as id0_0_, vocabulary2_.available as available0_0_, vocabulary2_.value as value0_0_, vocabulary2_.type as type0_0_ from vocabulary this_ left outer join vocabulary_value vocabulary2_ on this_.default_value=vocabulary2_.id where this_.klass=?
> 15:50:55,481 DEBUG AbstractBatcher:424 - preparing statement
> 15:50:55,495 DEBUG GooGooStatementCache:381 - cxnStmtMgr.statementSet( org.postgresql.jdbc3.Jdbc3Connection@650892 ).size(): 1
> 15:50:55,500 DEBUG GooGooStatementCache:117 - checkoutStatement:
> com.mchange.v2.c3p0.stmt.GlobalMaxOnlyStatementCache stats -- total size: 1; checked out: 1; num connections: 1; num keys: 1
> 15:50:55,511 DEBUG StringType:79 - binding ''uk.co.iizuka.advice.MethodOfContact'' to parameter: 1
> The last debug line seems a possibility for the error as the binding classname has double quotes around it. When using the "Restrictions.in" method, there are only single quotes.
--
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, 8 months
[Hibernate-JIRA] Updated: (HHH-1369) Restrictions.eq In Criteria Not matching a property of type java.lang.Class
by David CLEMENT (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1369?page=c... ]
David CLEMENT updated HHH-1369:
-------------------------------
Attachment: criteriaclass.zip
test case for the problem
> Restrictions.eq In Criteria Not matching a property of type java.lang.Class
> ---------------------------------------------------------------------------
>
> Key: HHH-1369
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1369
> Project: Hibernate3
> Issue Type: Bug
> Components: query-criteria
> Affects Versions: 3.1
> Environment: HB 3.1, Hibernate annotations 3.1-beta-7, Postgres 8.0.3
> Reporter: Matt Todd
> Attachments: criteriaclass.zip
>
>
> When using criteria query to get an entity using the following method:
> session.createCriteria(Vocabulary.class).add(Restrictions.eq("klass", MethodOfContact.class)).uniqueResult()
> No results are returned. Using an alternative method:
> session.createCriteria(Vocabulary.class).add(Restrictions.in("klass", new Object[] {MethodOfContact.class})).uniqueResult()
> returns the correct result.
> The annotations on the mapped class are:
> @Column(unique=true, nullable = false)
> private Class klass;
> The error is possibly comming from here looking at the debug:
> 15:50:55,479 DEBUG SQL:346 - /* criteria query */ select this_.id as id1_1_, this_.default_value as default5_1_1_, this_.name as name1_1_, this_.klass as klass1_1_, this_.type as type1_1_, vocabulary2_.id as id0_0_, vocabulary2_.available as available0_0_, vocabulary2_.value as value0_0_, vocabulary2_.type as type0_0_ from vocabulary this_ left outer join vocabulary_value vocabulary2_ on this_.default_value=vocabulary2_.id where this_.klass=?
> Hibernate: /* criteria query */ select this_.id as id1_1_, this_.default_value as default5_1_1_, this_.name as name1_1_, this_.klass as klass1_1_, this_.type as type1_1_, vocabulary2_.id as id0_0_, vocabulary2_.available as available0_0_, vocabulary2_.value as value0_0_, vocabulary2_.type as type0_0_ from vocabulary this_ left outer join vocabulary_value vocabulary2_ on this_.default_value=vocabulary2_.id where this_.klass=?
> 15:50:55,481 DEBUG AbstractBatcher:424 - preparing statement
> 15:50:55,495 DEBUG GooGooStatementCache:381 - cxnStmtMgr.statementSet( org.postgresql.jdbc3.Jdbc3Connection@650892 ).size(): 1
> 15:50:55,500 DEBUG GooGooStatementCache:117 - checkoutStatement:
> com.mchange.v2.c3p0.stmt.GlobalMaxOnlyStatementCache stats -- total size: 1; checked out: 1; num connections: 1; num keys: 1
> 15:50:55,511 DEBUG StringType:79 - binding ''uk.co.iizuka.advice.MethodOfContact'' to parameter: 1
> The last debug line seems a possibility for the error as the binding classname has double quotes around it. When using the "Restrictions.in" method, there are only single quotes.
--
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, 8 months
[Hibernate-JIRA] Updated: (HHH-1195) Criteria.list() not auto-flushing dirty many-to-many collection for entity used in criteria
by Gail Badner (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1195?page=c... ]
Gail Badner updated HHH-1195:
-----------------------------
Attachment: HHH-1195-test.patch
ManyToManyTest.java
I've updated org.hibernate.test.manytomany.ManyToManyTest to reproduce this issue in 3.2.3. I've attached both ManyToManyTest.java and a patch file for the update.
The updated test case includes tests that:
1) does a flush before executing a Criteria (succeeds)
2) does not do flush before executing a criteria (fails)
3) executes a Query instead of a Criteria (succeeds)
Gail Badner
SourceLabs - http://www.sourcelabs.com
Dependable Open Source Systems
> Criteria.list() not auto-flushing dirty many-to-many collection for entity used in criteria
> -------------------------------------------------------------------------------------------
>
> Key: HHH-1195
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1195
> Project: Hibernate3
> Issue Type: Bug
> Components: core
> Affects Versions: 3.0.5
> Reporter: Maik Schreiber
> Assignee: Gavin King
> Attachments: collection-query-spaces-3.1.2.patch, collection-query-spaces.patch, HHH-1195-test.patch, ManyToManyTest.java
>
>
> The following code first loads up a Parent entity, then clears its "children" collection. After that, a Criteria query is executed loading up all parents having a specific Child - which is the child that has been removed from the collection before. Thus, no parent should be found. However, this only works when flush()ing the session before running the Criteria query. Without flush, it finds the parent entity which it shouldn't.
> (If you need a more "runnable" test case, I'll be happy to provide one.)
> Code:
> Parent parent = (Parent) session.load(Parent.class, new Integer(1));
> Child child = (Child) session.load(Child.class, new Integer(1));
> System.out.println("before: " + parent.getChildren().size() + " (should be >0)");
> parent.getChildren().clear();
> System.out.println("after: " + parent.getChildren().size() + " (should be =0)");
> // must have flush() here for Criteria query
> session.flush();
>
> Criteria criteria = session.createCriteria(Parent.class)
> .createCriteria("children")
> .add(Restrictions.idEq(child.getId()));
> List parents = criteria.list();
>
> System.out.println("found " + parents.size() + " parents, should be =0");
> Mapping:
> <hibernate-mapping>
> <class
> name="de.blizzy.test.Parent"
> table="PARENT"
> lazy="true">
> <id
> name="id"
> column="parent_id"
> type="java.lang.Integer"
> unsaved-value="null">
>
> <generator class="native"/>
> </id>
> <set
> name="children"
> table="PARENT_2_CHILD"
> inverse="false"
> lazy="true">
>
> <key column="parent_id"/>
> <many-to-many
> class="de.blizzy.test.Child"
> column="child_id"/>
> </set>
> </class>
> </hibernate-mapping>
> <hibernate-mapping>
> <class
> name="de.blizzy.test.Child"
> table="CHILD"
> lazy="true">
> <id
> name="id"
> column="child_id"
> type="java.lang.Integer"
> unsaved-value="null">
>
> <generator class="native"/>
> </id>
> </class>
> </hibernate-mapping>
--
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, 9 months
[Hibernate-JIRA] Updated: (HHH-1189) interfaces for Proxies are not regonized as interfaces
by Benoit Goudreault-Emond (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1189?page=c... ]
Benoit Goudreault-Emond updated HHH-1189:
-----------------------------------------
Attachment: eg.zip
This code sample is a Maven project that builds against 3.2.2 GA and reproduces the problem in the test case (simply run "mvn test").
Briefly, this occurs when subclasses are given interfaces, but the parent class does not implement one. Note how DoctorImpl has a proxy declaration, but not Person.
Why would one do this? Well, in cases where a few extra methods are used only for certain subclasses, it is important to provide them through an interface so they are accessible even if the class returned by Hibernate is a proxy. Putting all methods of the base class in some base interface does fix the problem, but it's an annoying extra step.
Note that even if the bug described here is fixed, there are other problems in those situations, especially in the presence of access="field". I'm currently trying to isolate this. I suspect HHH-1953 is related to that problem.
> interfaces for Proxies are not regonized as interfaces
> ------------------------------------------------------
>
> Key: HHH-1189
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1189
> Project: Hibernate3
> Issue Type: Patch
> Components: core
> Affects Versions: 3.1 rc3
> Environment: Discovered on Hibernate 3.0, still present in 3.1rc3
> Reporter: Tobias
> Assignee: Steve Ebersole
> Priority: Critical
> Attachments: eg.zip
>
> Original Estimate: 1 hour
> Remaining Estimate: 1 hour
>
> In org.hibernate.tuple.PojoEntityTuplizer line 119 reads:
> if ( !proxyInterface.isInterface() ) {
> and should be
> if ( !subclassClass.isInterface() ) {
> So the code then would look like this:
> Subclass subclass = ( Subclass ) iter.next();
> Class subclassProxy = subclass.getProxyInterface();
> Class subclassClass = subclass.getMappedClass();
> if ( subclassProxy!=null && !subclassClass.equals( subclassProxy ) ) {
> if ( !subclassProxy.isInterface() ) { // HERE!
> throw new MappingException(
> "proxy must be either an interface, or the class itself: " +
> subclass.getEntityName()
> );
> }
> proxyInterfaces.add( subclassProxy );
> }
> After that change the specified interfaces for subclass proxies are regonized as such. Without this patch the superclass is checked, which may not have/be an interface as proxy class.
--
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, 9 months
[Hibernate-JIRA] Created: (HSHARDS-5) Syntax errors in documentation code for Obtaining a ShardedSessionFactory
by Nathan Silberman (JIRA)
Syntax errors in documentation code for Obtaining a ShardedSessionFactory
-------------------------------------------------------------------------
Key: HSHARDS-5
URL: http://opensource.atlassian.com/projects/hibernate/browse/HSHARDS-5
Project: Hibernate Shards
Issue Type: Bug
Components: documentation
Affects Versions: 3.0.0.Beta1
Reporter: Nathan Silberman
Assignee: Max Ross
Priority: Trivial
The 3rd code block in section 2.2. Obtaining a ShardedSessionFactory contains several trivial syntax errors. The following block contains the corrected code with commonts pointing out the corrections.
1 public SessionFactory createSessionFactory() {
2 Configuration prototypeConfig = new Configuration().configure("shard0.hibernate.cfg.xml");
3 prototypeConfig.addResource("weather.hbm.xml");
4 List<Configuration> shardConfigs = new ArrayList<Configuration>();
5 shardConfigs.add(new Configuration().configure("shard0.hibernate.cfg.xml") ); // added parenthasis
6 shardConfigs.add(new Configuration().configure("shard1.hibernate.cfg.xml") ); // added parenthasis
7 shardConfigs.add(new Configuration().configure("shard2.hibernate.cfg.xml") ); // added parenthasis
8 ShardStrategyFactory shardStrategyFactory = buildShardStrategyFactory();
9 ShardedConfiguration shardedConfig = new ShardedConfiguration(
10 prototypeConfig,
11 shardConfigs,
12 shardStrategyFactory);
13 return shardedConfig.buildShardedSessionFactory();
14 }
15
16 ShardStrategyFactory buildShardStrategyFactory() {
17 ShardStrategyFactory shardStrategyFactory = new ShardStrategyFactory() { // classname changed FROM StrategyFactory
18 public ShardStrategy newShardStrategy(List shardIds) {
19 RoundRobinShardLoadBalancer loadBalancer = new RoundRobinShardLoadBalancer(shardIds);
20 ShardSelectionStrategy pss = new RoundRobinShardSelectionStrategy(loadBalancer);
21 ShardResolutionStrategy prs = new AllShardsShardResolutionStrategy(shardIds);
22 ShardAccessStrategy pas = new SequentialShardAccessStrategy();
23 return new ShardStrategyImpl(pss, prs, pas);
24 }
25 }; // added semi-colon here
26 return shardStrategyFactory;
27 }
--
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, 9 months