[Hibernate-JIRA] Commented: (HHH-817) using projections is causing SQL query error on oracle (ORA-00904 error)
by Kevin Schmidt (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-817?page=co... ]
Kevin Schmidt commented on HHH-817:
-----------------------------------
Chris,
I appreciate your help with this issue. I am using the Hibernate AliasToBean results transformer to effectivly lazy load specific properties of my Criteria and Queryies. Essentially adding aliases with the same names as the properties to the criteria and then using the result transformer to only load the properties that are mentioned in the aliases. As such this issue was causing me problems, I made a minor change to your class that fixed an issue where the wrong column was being returned.
Here is the fix.
/**
* Override to use the property's column if we have it (which we should).
* Hack alert: This assumes that toSqlString gets called beforehand, which seems to be the case.
*
* @author kevinrs
* Note, I had to hack his hack so that this worked correctly. It first checks if the given alias is backed by this Object, and only then
* returna the column property value.
*
* @see org.hibernate.criterion.AliasedProjection#getColumnAliases(java.lang.String, int)
*/
public String[] getColumnAliases(String alias, int loc) {
String[] returnValue = null;
if(this.getAliases()[0].equals(alias) && propertyColumn != null) {
returnValue = new String[] {propertyColumn};
} else {
returnValue = super.getColumnAliases(alias, loc);
}
return returnValue;
}
Thanks so much for your help
> 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, 4 months
[Hibernate-JIRA] Created: (EJB-311) @Temporal annotations is not mandatory
by Rubem Azenha (JIRA)
@Temporal annotations is not mandatory
--------------------------------------
Key: EJB-311
URL: http://opensource.atlassian.com/projects/hibernate/browse/EJB-311
Project: Hibernate Entity Manager
Issue Type: Bug
Components: EntityManager
Affects Versions: 3.3.1.GA
Environment: hibernate-entitymanager-3.3.1.GA
hibernate-3.2
hibernate-annotations-3.3.0.GA
Reporter: Rubem Azenha
Priority: Minor
According to the JPA spec (section 9.1.20): "The Temporal annotation *must* be specified for persistent fields or properties of type
java.util.Date and java.util.Calendar."
But the Hibernate Entity manager allows attributes without the @Temporal annotation. According to the specs, it should be mandatory the use of the @Temporary annotation in java.util.Date and java.util.Calendar fields.
The Oracle TopLink Essentials - 2.0 (Build b41-beta2 (03/30/2007) JPA implementation throws a ValidationException in that cases.
--
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, 4 months
[Hibernate-JIRA] Created: (HV-39) Validator class does not retrieve the property name on array - The property name is the index of array !?
by Jorelia ANDRE (JIRA)
Validator class does not retrieve the property name on array - The property name is the index of array !?
---------------------------------------------------------------------------------------------------------
Key: HV-39
URL: http://opensource.atlassian.com/projects/hibernate/browse/HV-39
Project: Hibernate Validator
Issue Type: Bug
Affects Versions: 3.0.0.ga
Environment: Unix and Windows with RAD 7 (websphere) - JAVA 5.0 - JSF + JBoss Seam 1.2.1, facelet v1.1.12.
Reporter: Jorelia ANDRE
Attachments: validator-bugArray-2.PNG, validator-bugArray.PNG
Bonjour Emmanuel,
I've created a custom validator by using hibernate validator framework. So, I've put the new annotation on array of string (myString[] = new String[10]). Then I've used <s:validateAll> from JBoss Seam to validate the backing bean but unfortunately the isValid() method is never called. The reason is that the ClassValidator.java cannot retrieve properly the property name. Instead of, the property name is the index of the element !!!
Here is the case sample:
====================
The XHTML PAGE:
-------------------------
<!-- -->
<!-- 10 PRODUCTS -->
<!-- -->
<div class="colonneData">
<h:inputText id="numProduit1" value="#{myBean.product[0]}" />
</div>
<div class="colonneData">
<h:inputText id="numProduit1" value="#{myBean.product[1]}" />
</div>
<div class="colonneData">
<h:inputText id="numProduit1" value="#{myBean.product[2]}" />
</div>
etc.....
The BEAN PAGE:
-------------------------
@Name("myBean")
@Scope(CONVERSATION)
@AutoCreate
public class myBean extends ControleurPresentation {
@CheckProductNumber
private String[] product= new String[10];
}
The VALIDATOR
-------------------------
public class CheckProductNumberValidator implements Validator<CheckProductNumber> {
public boolean isValid(Object value) {
/* your validation code */
return true;
}
}
UNDER THE DEBUGGER
=====================
Hibernate code:
============
/**
* Apply constraints of a particular property value of a bean type and return all the failures.
* The InvalidValue objects returns return null for InvalidValue#getBean() and InvalidValue#getRootBean()
* Note this is not recursive.
*/
//TODO should it be recursive?
public InvalidValue[] getPotentialInvalidValues(String propertyName, Object value) {
List<InvalidValue> results = new ArrayList<InvalidValue>();
for ( int i = 0; i < memberValidators.size() ; i++ ) {
XMember getter = memberGetters.get( i );
if ( getPropertyName( getter ).equals( propertyName ) ) {
Validator validator = memberValidators.get( i );
if ( !validator.isValid( value ) ) {
results.add( new InvalidValue( interpolate(validator), beanClass, propertyName, value, null ) );
}
}
}
return results.toArray( new InvalidValue[results.size()] );
}
>>>>>>>>>>> So, the parameter propertyName has the value of "0" !!!!! and the test if ( getPropertyName( getter ).equals( propertyName ) ) failed because there is no getter for "0" !!!! of course.
The valueBinding of the UIComponent is :
/pages/materielPromo/rechercheMultiCriteres.xhtml @70,203 value="#{myBean.product[0]}"
Probably that the bug is in extracting the property.
Please could you confirm the bug ASAP and give any workaround.
Thank you very much.
NOTE: (I'm pretty sure that somebody I've already requested that...)
=====
1) @Valid should work for array of string String[] - Most of validator should work with array of String and Integer
2) Validators should implement setter and getter to be able to reuse them in the case to build our own validator by calling yours.
3) More Javadoc on validator class will help and good for the community.
Thank you in advance.
--
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, 4 months
[Hibernate-JIRA] Commented: (HHH-1869) The MultipleHiloPertablegenerator.class wraps at 2**31-1, but javadoc claims Long.
by Stephen Hiley (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1869?page=c... ]
Stephen Hiley commented on HHH-1869:
------------------------------------
This is one of those insidious bugs, as it does not blow up at runtime, but instead returns the wrong value. We were burned by this in our production environment. The code fix offered by the reporter here is spot on! The number being loaded into hival from doWorkInNewTransaction() should be a long. And the following multiplication should be cast for clarity as shown in the attached version.
Offending code:
org.hibernate.id.MultipleHiLoPerTableGenerator
hi = hival * (maxLo+1);
where hival and maxLo are both ints. The result, hi, is a long. But that doesn't matter to java when it does the computation. It computes the result as an int, overflows the max lengh, then casts the result to along. To fix, one just needs to cast the result explicitely, or change hival to be a long (see bug reporter's code).
Here's the JUnit test I wrote to prove this.
@Test public void testIntToLong()
{
int hival = 34550207;
int maxLo = 5000;
long uncastHi = hival * (maxLo + 1);
long expectedHi = (long) hival * (maxLo + 1);
assertEquals("Wishing these two results matched!", expectedHi, uncastHi);
}
Yields: junit.framework.AssertionFailedError: Wishing these two results matched! expected:<172785585207> but was:<986893367>
The test fails, demonstrating the bug in the generate() method. Interestingly, this problem was not duplicated in the TableHiLoGenerator in the same package, in that it sets the return value of the super.generate() as a long.
long val = ( (Number) super.generate(session, obj) ).longValue();
But it does suffer from treating that returned hival from the database as an Integer, which will suffer the same truncation problems once your hival grows beyond the max size of a java int. Perhaps this should be handled as a seperate bug.
> The MultipleHiloPertablegenerator.class wraps at 2**31-1, but javadoc claims Long.
> ----------------------------------------------------------------------------------
>
> Key: HHH-1869
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1869
> Project: Hibernate3
> Issue Type: Bug
> Components: core
> Affects Versions: 3.2.0 cr1
> Environment: All versions/all environments.
> Reporter: Jan Helge Salvesen
> Attachments: MultipleHiLoPerTableGenerator.zip
>
>
> The returntype of org.hibernate.id.MultipleHiloPertablegenerator.doWorkInCurrentTransaction are Serializable, and the javadoc states that this class shall return a Long (line 26 in source-file). But the value to be returned are, in fact, treated as an Integer and thus limited to 31-bits positive numbers (as an Integer). See line 163 in class, for instance. This behaviour will cause problems for sequence numbers above Integer.MAX_VALUE (that is 2**31-1). When this limit is exceeded, the actual returned "Long" are a huge-negative integer and may potentinally cause damage. The reason for Priority:Major is the fact that user of this class may have an old-fashon databasescheme, and for this reason, this error may become a "ticking bomb" waiting to a sequence number to exceed 2**31-1.
> The fixup are trivial. The internal representation of the number must be Long, and user shall be urged to upgrade to new release.
> I have attached a fixed version of the MultipleHiloPertablegenerator.java where the generated sequencenumber are treated as a long. I have allso tested my modified version and verified that the sequence-generation part on a Oracle system works as expected, which is that the generated sequence actually can exceed 2**31-1.
> (I have not tested the schema-generate-part, since this is not critical for user.)
--
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, 4 months
[Hibernate-JIRA] Created: (HHH-2803) Subqueries.propertyIn creates wrong SQL for the where clause. Where clause is on ID and not on named property - resulting in wrong resultset.
by Philip Saville (JIRA)
Subqueries.propertyIn creates wrong SQL for the where clause. Where clause is on ID and not on named property - resulting in wrong resultset.
---------------------------------------------------------------------------------------------------------------------------------------------
Key: HHH-2803
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2803
Project: Hibernate3
Issue Type: Bug
Components: core
Affects Versions: 3.2.4.sp1
Environment: Hibernate 3 (Hibernate-Version: 3.2.4.sp1)
MySql 4,.1 MSSQL 2000
Reporter: Philip Saville
class User {
...
private List<Role> roles;
...
@ManyToMany(...)
@JoinTable(...)
public List<Role> getRoles() {...{
}
DetachedCriteria subQuery = DetachedCriteria.forClass(Role.class);
subQuery.add(Restrictions.in("id", values)); // a list of know user roles to search on
// work around for bug:993
subQuery.setProjection(Projections.property("id"));
DetachedCriteria users = DetachedCriteria.forClass(User.class);
users.add(Subqueries.propertyIn("roles", subQuery));
This results in:
select this_.ID as ID17_1_, this_.LOCK_VERSION as LOCK2_17_1_, this_.GIVEN_NAME as GIVEN6_17_1_, this_.PASSWORD as PASSWORD17_1_, this_.SURNAME as SURNAME17_1_, this_.USER_NAME as USER12_17_1_, roles2_.USER_ID as USER1_3_, role3_.ID as ROLE2_3_, role3_.ID as ID18_0_, role3_.LOCK_VERSION as LOCK2_18_0_, role3_.DESCRIPTION as DESCRIPT3_18_0_, role3_.LEVEL as LEVEL18_0_, role3_.NAME as NAME18_0_ from T_USER this_ left outer join USER_ROLE roles2_ on this_.ID=roles2_.USER_ID left outer join ROLE role3_ on roles2_.ROLE_ID=role3_.ID where this_.ID = (select this0__.ID as y0_ from ROLE this0__ where this0__.ID in (?)) order by this_.USER_NAME asc)
Note - the where clause is on User.ID not, User.roles...
--
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, 4 months
[Hibernate-JIRA] Created: (HHH-2626) Bug in handling null references to Components / Embeddables when using session / entityManager.merge()
by Michael Plöd (JIRA)
Bug in handling null references to Components / Embeddables when using session / entityManager.merge()
------------------------------------------------------------------------------------------------------
Key: HHH-2626
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2626
Project: Hibernate3
Issue Type: Bug
Affects Versions: 3.2.4.sp1, 3.2.4, 3.2.3
Environment: Hibernate 3.2.3 - 3.2.4.sp1; Any Database
Reporter: Michael Plöd
Priority: Critical
Attachments: patch.txt, TestCase.zip
I found a bug, that got introduced by adding functionality to the class TypeFactory in Hibernate 3.2.3. The Method TypeFactory#replaceAssociations(...) now has some special handling regarding components / embeddables. But if such a component is null, wich is fair enough, Hibernate will provoke a NullPointerException in sun.reflect.UnsafeFieldAccessorImpl.ensureObj(...):
Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.PropertyAccessException: could not get a field value by reflection getter of de.ploed.test.MonetaryAmount.amount
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:647)
at org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:236)
at de.ploed.test.EntityManagerTest.main(EntityManagerTest.java:22)
Caused by: org.hibernate.PropertyAccessException: could not get a field value by reflection getter of de.ploed.test.MonetaryAmount.amount
at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:35)
at org.hibernate.tuple.component.AbstractComponentTuplizer.getPropertyValue(AbstractComponentTuplizer.java:64)
at org.hibernate.tuple.component.AbstractComponentTuplizer.getPropertyValues(AbstractComponentTuplizer.java:70)
at org.hibernate.tuple.component.PojoComponentTuplizer.getPropertyValues(PojoComponentTuplizer.java:83)
at org.hibernate.type.ComponentType.getPropertyValues(ComponentType.java:353)
at org.hibernate.type.ComponentType.getPropertyValues(ComponentType.java:348)
at org.hibernate.type.TypeFactory.replaceAssociations(TypeFactory.java:556)
at org.hibernate.event.def.DefaultMergeEventListener.copyValues(DefaultMergeEventListener.java:366)
at org.hibernate.event.def.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:195)
at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:123)
at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:53)
at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:677)
at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:661)
at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:665)
at org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:227)
... 1 more
Caused by: java.lang.NullPointerException
at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:36)
at sun.reflect.UnsafeObjectFieldAccessorImpl.get(UnsafeObjectFieldAccessorImpl.java:18)
at java.lang.reflect.Field.get(Field.java:357)
at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:32)
... 15 more
I think that the handling of target[i] in Line 556 of org.hibernate.type.TypeFactory is not null safe. I have created a patch for this and the bug above appears to be fixed in this patch.
In my humble opinion this bug makes it impossible to merge any entity / value object containing a null reference to another value object.
However this bug is not present when using session.save or session.saveOrUpdate.
I was able to reproduce the bug in Hibernate Core 3.2.4.sp1, 3.2.4 and 3.2.3 .. It is not present in Hibernate Core Versions <= 3.2.2
Attached to this task are the following files:
patch.txt - my patch proposal
TestCase.zip - Test Case
Please get back to me if you have any further questions!
Cheers,
Mike
--
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, 4 months
[Hibernate-JIRA] Created: (HHH-2800) Support for "DISTINCT ON"
by Petr Ferschmann (JIRA)
Support for "DISTINCT ON"
-------------------------
Key: HHH-2800
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2800
Project: Hibernate3
Issue Type: New Feature
Components: query-hql
Environment: PostgreSQL 8.1, Hibernate 3.2.1.ga
Reporter: Petr Ferschmann
I want to use equivalent of "distinct on" in PostgreSQL.
If I have data like that:
create table tbl (
F1 char,
F2 char
);
F1, F2
| A | 1 |
| A | 2 |
| B | 1 |
for query:
select distinct on (F1) F1, F2 from tbl
I get:
A, 1
B, 1
Currently "distinct on (xxx, xxx)" (no comma here) is not valid for HQL parser:
org.hibernate.hql.ast.QuerySyntaxException: unexpected token: on near line 1, column 17 [select distinct on (this.ID) this, p from ...]
org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:31)
org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:24)
org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:59)
org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:258)
org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:157)
org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
For my usage it is enough to pass this syntax to SQL server. The current meaning of "DISTINCT" in Hibernate is not enough because we are working with large data sets and it is not even usable for 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, 4 months