[Hibernate-JIRA] Created: (HHH-3128) NullPointerException while building SessionFactory when using native sql query for loading many-to-many mapped collections
by Juergen Denzel (JIRA)
NullPointerException while building SessionFactory when using native sql query for loading many-to-many mapped collections
--------------------------------------------------------------------------------------------------------------------------
Key: HHH-3128
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3128
Project: Hibernate3
Issue Type: Bug
Affects Versions: 3.2.6, 3.2.5
Environment: Hibernate 3.2.6
Reporter: Juergen Denzel
Attachments: src.zip
Hi,
I am trying to load a many-to-many mapped collection using a sql query like this:
<sql-query name="loadItems">
<load-collection alias="item" role="test.Test.items"/>
select {item.*} from Items item where item.id = :id
</sql-query>
This always fails due to a NullPointerException:
java.lang.NullPointerException
at org.hibernate.loader.custom.sql.SQLQueryParser.resolveProperties(SQLQueryParser.java:182)
at org.hibernate.loader.custom.sql.SQLQueryParser.resolveCollectionProperties(SQLQueryParser.java:135)
at org.hibernate.loader.custom.sql.SQLQueryParser.substituteBrackets(SQLQueryParser.java:98)
at org.hibernate.loader.custom.sql.SQLQueryParser.process(SQLQueryParser.java:51)
at org.hibernate.loader.custom.sql.SQLCustomQuery.<init>(SQLCustomQuery.java:110)
at org.hibernate.engine.query.NativeSQLQueryPlan.<init>(NativeSQLQueryPlan.java:43)
at org.hibernate.engine.query.QueryPlanCache.getNativeSQLQueryPlan(QueryPlanCache.java:114)
at org.hibernate.impl.SessionFactoryImpl.checkNamedQueries(SessionFactoryImpl.java:446)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:352)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1300)
at test.HibernateTest.testSessionFactory(HibernateTest.java:18)
I provided a very simple TestCase + Mappings to illustrate the problem. The exception does not occur for one-to-many mappings.
Just for your information, we need this functionality in order to deal with DB2 problems we have.
I ran this TestCase against 3.2.5 and 3.2.6 and both failed.
Thanks.
Juergen Denzel
--
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
15 years, 8 months
[Hibernate-JIRA] Created: (EJB-423) Smarter Joins - One instead of Two
by Bradford (JIRA)
Smarter Joins - One instead of Two
----------------------------------
Key: EJB-423
URL: http://opensource.atlassian.com/projects/hibernate/browse/EJB-423
Project: Hibernate Entity Manager
Issue Type: Improvement
Components: EntityManager
Affects Versions: 3.3.1.GA
Environment: Hibernate with PostgreSQL
Reporter: Bradford
Priority: Minor
I have CompanyLocation that has a station property as ManyToOne with Station. StationLocale has a station property as ManyToOne with Station. I created a OneToMany relationship in Station that's called localizedStation.
If I write the following:
left join colocs.station.localizedStation as sl
It creates two left joins when it gets converted to SQL:
left outer join stations station4_
on companyloc0_.station_code=station4_.code
left outer join station_locales localizeda5_
on station4_.code=localizeda5_.station_code
This is a waste. Shouldn't it be smart enough to generate the following:
left outer join station_locales localizeda5_
on companyloc0_.station_code=localizeda5_.station_code
--
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
15 years, 8 months
[Hibernate-JIRA] Commented: (HHH-1491) wrong set size() with lazy="extra" and where="..."
by Dan McGee (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1491?page=c... ]
Dan McGee commented on HHH-1491:
--------------------------------
This is still not working for where clauses, and it appears the SQL generated for count(*) queries also does not respect <filter> or @Filter statements in addition to the where clause documented here and in HHH-3319.
> wrong set size() with lazy="extra" and where="..."
> --------------------------------------------------
>
> Key: HHH-1491
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1491
> Project: Hibernate Core
> Issue Type: Bug
> Components: core
> Affects Versions: 3.1.2
> Reporter: Renat Yusupov
> Attachments: AbstractCollectionPersister.patch, HHH1491.jar
>
>
> In mapping file if set lazy = "extra" to set and additionaly set some "where" attribute we have wrong size() returned if collection does not initalized. sql query just ignore additional where clause.
> example:
> Collection children = parent.getChildren();
>
> System.out.println("Result = "+children.size());
>
> for ( Iterator iter = children.iterator(); iter.hasNext(); )
> {
> //skip
> }
>
> System.out.println("Result = "+children.size());
> first result is greater that second.
> part of mapping:
> <set name="children" inverse="true" lazy="extra" where="system='f'">
> if we use lazy="true" all ok.
--
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
15 years, 8 months
[Hibernate-JIRA] Commented: (HHH-817) Aggregate projection aliases should not be applied to where-clause
by David (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-817?page=co... ]
David commented on HHH-817:
---------------------------
Okay, so maybe this won't ever get fixed, the correct workaround to lazy load a property using projections:
Create a criteria,
build your projection list...
ProjectionList cols = Projections.projectionList();
Add the columns you want to be loaded on your object, to your projection list.
Make sure you include your identity property in your projection list, but don't include any column you want to query against
(see why this stinks?)
This means I can't ever lazy-load an object using its identity, unless I want to track / set it manually.
> Aggregate projection aliases should not be applied to where-clause
> ------------------------------------------------------------------
>
> Key: HHH-817
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-817
> Project: Hibernate Core
> Issue Type: Bug
> Components: core
> 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
15 years, 8 months