[Hibernate-JIRA] Created: (HHH-4615) index() not working with maps and map-key-many-to-many
by Michael Wyraz (JIRA)
index() not working with maps and map-key-many-to-many
------------------------------------------------------
Key: HHH-4615
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4615
Project: Hibernate Core
Issue Type: Bug
Affects Versions: 3.3.2, 3.2.7
Reporter: Michael Wyraz
I have 2 mapped entities:
EntityA [ id:long, testMap:Map<EnityB,Integer>, some other properties ]
EntityB [ id:long, some other properties ]
The mapping of EntityA is like:
<class name="EntityA">
<id name="id">...</id>
<map name="testMap" table="a_to_b">
<key column="a_id"/>
<map-key-many-to-many column="b_id" class="EntityB"/>
<element type="integer" column="int_value"/>
</map>
</class>
Now I want to query all EntityA with a certain EnityB as map key:
1.
"from a EntityA left join a.testMap b where index(b).id=?"
Parameter: <Long> (id of an EntityB)
15:35:12,349 ERROR PARSER:56 - <AST>:1:94: unexpected AST node: (
java.lang.NullPointerException
at org.hibernate.hql.ast.HqlSqlWalker.lookupProperty(HqlSqlWalker.java:534)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.addrExpr(HqlSqlBaseWalker.java:4543)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1289)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:4243)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:3722)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1864)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1792)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:818)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:604)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:288)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:231)
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:94)
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:1651)
[...]
2.
"from a EntityA left join a.testMap b where index(b)=?"
Parameter: <Long> (id of an EntityB)
This is really strange: it tries to run the getter of EnityB.id againt a <Long>
org.hibernate.PropertyAccessException: could not get a field value by reflection getter of test.EntityB.id
at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:58)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:199)
at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:3605)
[...]
Caused by: java.lang.IllegalArgumentException: Can not set long field test.EntityB.id to java.lang.Long
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:146)
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:150)
at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:37)
at sun.reflect.UnsafeLongFieldAccessorImpl.getLong(UnsafeLongFieldAccessorImpl.java:42)
at sun.reflect.UnsafeLongFieldAccessorImpl.get(UnsafeLongFieldAccessorImpl.java:18)
at java.lang.reflect.Field.get(Field.java:358)
at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:55)
... 67 more
3.
"from a EntityA left join a.testMap b where index(b)=?"
Parameter: <EntityB>
15:40:24,935 INFO IntegerType:158 - could not bind value '2009219112005957163' to parameter: 1; java.lang.Long cannot be cast to java.lang.Integer
java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer
at org.hibernate.type.IntegerType.set(IntegerType.java:64)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:154)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:136)
at org.hibernate.param.PositionalParameterSpecification.bind(PositionalParameterSpecification.java:68)
at org.hibernate.loader.hql.QueryLoader.bindParameterValues(QueryLoader.java:514)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1593)
Here it thinks that the index() is of type integer.
--
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
14 years, 11 months
[Hibernate-JIRA] Created: (HHH-3743) MININDEX function applied on entity of many-to-many mapped collection yields incorrect SQL
by Stefan Wachter (JIRA)
MININDEX function applied on entity of many-to-many mapped collection yields incorrect SQL
------------------------------------------------------------------------------------------
Key: HHH-3743
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3743
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.3.1
Environment: Hibernate 3.3.1, org.hibernate.dialect.DerbyDialect and org.hibernate.dialect.MySQLInnoDBDialect
Reporter: Stefan Wachter
I have a "t_Person" entity with a "many-to-many" list to a "t_Address" entity:
<class entity-name="t_Person" table="F5_T_PERSON" lazy="true">
<id name="_id" column="ID" type="long">
<generator class="native"/>
</id>
<list lazy="true" cascade="all" name="elemAddress" table="F5_T_PERSON_ELM_ADDRESS">
<key column="OWNER_KEY"/>
<list-index column="IDX"/>
<many-to-many column="FOREIGN_KEY" entity-name="t_Address"/>
</list>
</class>
<class entity-name="t_Address" table="F5_T_ADDRESS" lazy="true">
<id name="_id" column="ID" type="long">
<generator class="native"/>
</id>
<property name="attrStreet" type="string">
<column name="A_STREET"/>
</property>
</class>
When I try to retrieve the minimum index of address entities using the following HQL
select MININDEX(a) from t_Person as p join p.elemAddress as a
incorrect SQL results:
select min(t_address2_.IDX) as col_0_0_ from F5_T_PERSON t_person0_ inner join F5_T_PERSON_ELM_ADDRESS elemaddres1_ on t_person0_.ID=elemaddres1_.OWNER_KEY inner join F5_T_ADDRESS t_address2_ on elemaddres1_.FOREIGN_KEY=t_address2_.ID
In particular the addressed column "t_address2_.IDX" does not exists. Instead "elemaddres1_.IDX" should be used because the index column is contained in the join table "F5_T_PERSON_ELM_ADDRESS".
I assume that the MININDEX function does not consider the case when it is applied to an element of a many-to-many collection.
I tested this with the DerbyDialect and the MySQLInnoDBDialect.
--
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
14 years, 11 months
[Hibernate-JIRA] Commented: (HHH-772) null in maps are handled inconsistently
by Michael Newcomb (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-772?page=co... ]
Michael Newcomb commented on HHH-772:
-------------------------------------
Just spent an hour trying to figure out what I was doing wrong... come to find out I wasn't doing anything wrong...
As to not obeying the Map api, on a new entity, the map you populate is your map until you persist the entity, so they can't really do anything at that point. Now when you load an entity PersistentMap could throw NullPointerException if someone tried to put a null value in. So, they can stop it on a Hibernate loaded entity, but not from one you just persisted. From that perspective it is inconsistent but they can't really do anything about it.
IMHO, since they can't do anything about it, they should *persist* everything they can in a map because the only alternative is inconsistency. I give you a map with some null values and Hibernate silently drops them on the floor. However, they are still in the map of the entity until a new one is loaded. That is by definition inconsistent.
Another alternative would be for Hibernate to throw an exception when a Map is persisted with null values. I could live with that.
On a positive note, Hibernate KICKS ASS and these issues are relatively minor.
On a negative note, there is an attitude of superiority that emanates from the direction of the Hibernate team that is not helpful and I think it causes some bugs to be dropped on the floor. HHH-3223 : Map.remove() is broken, yet a patch has existed for almost 2 years!
> null in maps are handled inconsistently
> ---------------------------------------
>
> Key: HHH-772
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-772
> Project: Hibernate Core
> Issue Type: Improvement
> Components: core
> Reporter: Max Rydahl Andersen
> Fix For: 3.1 beta 1
>
>
> regarding case 00004729.
> group.getUsers().put("something", null);
> Does not result in any insert.
> Inserting "something", null manually into the underlying table and
> when hibernate reads the map will have "something"->null in the map.
--
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
14 years, 11 months
[Hibernate-JIRA] Created: (HHH-3938) One-To-One Filter Applied, Non-Lazy Fetch Problem
by Sandeep Vaid (JIRA)
One-To-One Filter Applied, Non-Lazy Fetch Problem
-------------------------------------------------
Key: HHH-3938
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3938
Project: Hibernate Core
Issue Type: Improvement
Components: core
Affects Versions: 3.3.1
Reporter: Sandeep Vaid
Priority: Critical
Suppose i have one-to-one association between Product and ProductBasic. and we have applied filter on ProductBasic Class.
I have applied this filter as in Java side we have one-to-one relationship between Product and ProductBasic BUT at database side
we have one-to-many relationship between PRODUCT and PRODUCTBASIC. and we apply a condition (STARTTIME < CURRETTIME < ENDTIME)
while fetching PRODUCTBASIC, and this will always give me one record out of many.
So i have put this condition as filter in ProductBasic class.
In current hibernate, one-to-one associations are always non-lazily fetched. Moreover it doesn't apply filter conditions.
I understand that it can;t apply filter condition as some filter parameter must be provided at runtime and
user may not provide them (as he is not asking for ProductBasic)... Also in this case, proper proxy can't be created as
until we apply the filter criteria, we won't get one ProductBasic row (among many)..
I think hibernate code should be changed so that if a filter is declared on the associated class (ProductBasic in our case),
hibernate should return null for ProductBasic.
--
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
14 years, 11 months
[Hibernate-JIRA] Created: (HSEARCH-451) NativeQuery alias on column
by Tomaž (JIRA)
NativeQuery alias on column
----------------------------
Key: HSEARCH-451
URL: http://opensource.atlassian.com/projects/hibernate/browse/HSEARCH-451
Project: Hibernate Search
Issue Type: Bug
Components: query
Affects Versions: 3.2.0.CR1
Environment: OS: Win XP
Java: 1.6
Hibernate 3.2.5.ga
MySQL: 5.1
Reporter: Tomaž
Priority: Blocker
n a pure SQL I use alias on column(query is valid and server return true result) but Hibernate throw exception.
Also the problem is that the Hibernate retrieve wrong values for columns with the same name.
--------------------------------------------------
Example 1:
SQL = SELECT
organizacije.id,
koda.vrednost AS k,
tip.vrednost AS t
FROM
organizacije
LEFT JOIN
sif_kodorg AS koda
ON koda.id=organizacije.koda
LEFT JOIN
sif_tiporg AS tip
ON tip.id=organizacije.tip_org
WHERE
organizacije.id=64
EntityManager.createNativeQuery(SQL) // error
error: org.hibernate.exception.SQLGrammarException: could not execute query
------------------------------------------
Example 2:
SQL = SELECT
organizacije.id,
koda.vrednost,
tip.vrednost
FROM
organizacije
LEFT JOIN
sif_kodorg AS koda
ON koda.id=organizacije.koda
LEFT JOIN
sif_tiporg AS tip
ON tip.id=organizacije.tip_org
WHERE
organizacije.id=64
When retrieving result in a array I get the same value for both columns koda.vrednost, tip.vrednost
-----------------------------------
Why is here involved Hibernate Grammar if it's just a pure SQL, so is there any solutions how to retrieve values of columns with same name?
Regards, Tomaž
--
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
14 years, 11 months