[Hibernate-JIRA] Created: (HHH-3796) Non-ANSI92 compliant SQL is generated when binding null values
by Tom van den Berge (JIRA)
Non-ANSI92 compliant SQL is generated when binding null values
--------------------------------------------------------------
Key: HHH-3796
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3796
Project: Hibernate Core
Issue Type: Bug
Affects Versions: 3.2.6
Environment: HSQLDB
Reporter: Tom van den Berge
When binding a parameter with a null value to a query (using the JPA interface), Hibernate generates SQL that is not ANSI-92 SQL compliant. The JPAQL
Query q = ..."from entity where column = :possibleNullValue";
q.setParameter("possibleNullValue", null);
results in the following SQL:
"select ... from entity where column = null".
According to the ANSI-92 SQL standard, comparing with null values must always be done with the "is" operator. Using the equals (=) operator always evaulates to FALSE, and will therefore not produce any results.
Many databases relax this requirement and treat the equals operator similar to the "is" operator when comparing null values. However, HSQLDB does not (it enforces strict ANSI-92 compliance), which means that this kind of queries does not produce any results on this database. There are probably other database that do this, too.
Strangly enough, when the parameter is not bound to the query, but inserted in the JPAQL, Hibernate generates correct SQL:
"from entity where column = null"
is converted to SQL:
"select ... from entity where column is null".
So a workaround is to provide two different queries: one for non-null values (using parameter binding), and one for null values (using "null" in the JPAQL). Rather silly, but it works.
--
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, 10 months
[Hibernate-JIRA] Commented: (HHH-16) Explicit joins on unrelated classes
by radhakrishna (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-16?page=com... ]
radhakrishna commented on HHH-16:
---------------------------------
Sergey Pulyaev - 24/Jul/08 02:35 AM
HQL part of this issue is done as i know - but is there any progress on Criteria API development?
I mean Criteria API for JOIN ON <expression> logic...
Is this issue fixed, if so, where is the patch and when will it be added/provided by Hibernate themselves?
> Explicit joins on unrelated classes
> -----------------------------------
>
> Key: HHH-16
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-16
> Project: Hibernate Core
> Issue Type: New Feature
> Components: core
> Affects Versions: antlr-rework
> Environment: Any
> Reporter: David Lloyd
> Assignee: Steve Ebersole
> Fix For: antlr-rework
>
>
> It would be nice to be able to do explicit joins on unrelated classes with HQL:
> (hope this renders correctly)
> select empl, phone
> from org.example.Employee empl
> left outer join org.example.PhoneBook phone
> on phone.lastName = empl.lastName
> and phone.firstName = empl.firstName
> where empl.salaryGrade > 10
> Note that this would also implicity solve HB-1089 because you could list join criteria that match what Hibernate would have chosen anyway (i.e., list a many-to-one relationship as a criteria explicitly).
> Syntactically this could be disambiguated from the existing join syntax because the token after "join" is a class name rather than a property name.
--
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, 10 months
[Hibernate-JIRA] Created: (HHH-3797) Incorrect SQL syntax for EJB query involving Entity with composite Key
by Diego Palumbo (JIRA)
Incorrect SQL syntax for EJB query involving Entity with composite Key
----------------------------------------------------------------------
Key: HHH-3797
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3797
Project: Hibernate Core
Issue Type: Bug
Components: query-hql
Environment: Hibernate JPA (hibernate3.jar), Sql Server 2003
Reporter: Diego Palumbo
Hello.
I have some trouble with queries on Entities with composite key as follow:
select count(o) from Logqueryt as o
the key is LogquerytPK.java (see the follwing definition).
Now i'm not able to see the SQL generated but when i try to excute my project i receive an SQLGrammarException (see follow report)
I also red this issue (http://opensource.atlassian.com/projects/hibernate/browse/HHH-2266) where was considered the same problem but I didn't hunderstand if this could be considered a bug or if I have to use a different syntax for this kind of queries.
If it is a bug, was it fixed?
------------------LogquerytPK--------------------------------------------------
package entities;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Embeddable;
/**
*
* @author d.palumbo
*/
@Embeddable
public class LogquerytPK implements Serializable {
@Basic(optional = false)
@Column(name = "ID")
private int id;
@Basic(optional = false)
@Column(name = "ANNO")
private short anno;
public LogquerytPK() {
}
public LogquerytPK(int id, short anno) {
this.id = id;
this.anno = anno;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public short getAnno() {
return anno;
}
public void setAnno(short anno) {
this.anno = anno;
}
@Override
public int hashCode() {
int hash = 0;
hash += (int) id;
hash += (int) anno;
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof LogquerytPK)) {
return false;
}
LogquerytPK other = (LogquerytPK) object;
if (this.id != other.id) {
return false;
}
if (this.anno != other.anno) {
return false;
}
return true;
}
@Override
public String toString() {
return "entities.LogquerytPK[id=" + id + ", anno=" + anno + "]";
}
}
-------------------------------Exception-------------------------------------
4-mar-2009 10.12.20 org.hibernate.util.JDBCExceptionReporter logWarnings
AVVERTENZA: SQL Warning: 170, SQLState: 37000
4-mar-2009 10.12.20 org.hibernate.util.JDBCExceptionReporter logWarnings
AVVERTENZA: Preparing the statement failed: Line 1: Incorrect syntax near ','.
4-mar-2009 10.12.20 org.hibernate.util.JDBCExceptionReporter logExceptions
AVVERTENZA: SQL Error: 170, SQLState: 37000
4-mar-2009 10.12.20 org.hibernate.util.JDBCExceptionReporter logExceptions
GRAVE: Line 1: Incorrect syntax near ','.
javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:637)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:74)
at persistence.QueryTester.main(QueryTester.java:30)
Caused by: org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2223)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:65)
... 1 more
Caused by: java.sql.SQLException: Line 1: Incorrect syntax near ','.
at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:368)
at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2816)
at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2254)
at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:631)
at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQLQuery(JtdsStatement.java:477)
at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeQuery(JtdsPreparedStatement.java:777)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1787)
at org.hibernate.loader.Loader.doQuery(Loader.java:674)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2220)
... 9 more
---------------------------------------------------------------------------
--
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, 10 months
[Hibernate-JIRA] Created: (HHH-3522) Null value cannot be cache using hibernate
by Lao Shing Kit (JIRA)
Null value cannot be cache using hibernate
--------------------------------------------
Key: HHH-3522
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3522
Project: Hibernate Core
Issue Type: Bug
Components: caching (L2)
Environment: Hibernate 3.3.1, Ehcache 1.5, Java1.5
Reporter: Lao Shing Kit
I'm using Hibernate with 2nd level cache using Ehcache. We found that if the result returned using session.get() (searching by primary key) is NULL, the value will not be cached in 1st level and 2nd level cache and SQL will be fired to database. There is no problem if the value retuurned is not null for the same entity. I have debug using the hibernate and ehcache source and I'm sure that the cache is enabled and called properly. Actually the null value is expected to be cached also. I have browser all hibernate and ehcache documentation and forum and no related config is available. So, is it a bug?
Thanks all for your help!
--
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, 10 months
[Hibernate-JIRA] Created: (HHH-3455) Component polymorphism (<subclass> within <component>)
by Jasper Blues (JIRA)
Component polymorphism (<subclass> within <component>)
------------------------------------------------------
Key: HHH-3455
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3455
Project: Hibernate3
Issue Type: Improvement
Components: core
Reporter: Jasper Blues
The following feature request occurs on the Hibernate forums from time to time - it would be especially useful in mapping complex legacy schemas:
<class name="Critter">
<component name="breathingStrategy" class="BreathingStrategy">
<discriminator column="BREATHING_STRATEGY" type="integer" />
<subclass name="Lungs" discriminator-value="0" >
<set name="alveoli">
<key column="CRITTER_ID" />
<one-to-many class="Alveolus" />
</set>
</subclass>
<subclass name="Gills" discriminator-value="1" >
<set name="alveoli">
<key column="CRITTER_ID" />
<one-to-many class="Gill" />
</set>
</subclass>
</component>
</class>
Will a patch that implements this feature be accepted?
What do you think if there was an option to inherit a discriminator from the owning entity? How about some convention over configuration? By default the discriminator from the owning entity is inherited, unless one is supplied at the component level.
Would an equivalent annotation mapping be required?
--
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, 10 months
[Hibernate-JIRA] Created: (HHH-3794) Issue when method return type is Interface
by Amar Singh (JIRA)
Issue when method return type is Interface
------------------------------------------
Key: HHH-3794
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3794
Project: Hibernate Core
Issue Type: Bug
Components: envers
Reporter: Amar Singh
I came across this problem while using Hibernate-envers-3.4-SNAPSHOT with Hibernate-3.3.GA or Hibernate-3.4-SNAPSHOT. Below is my hbm.xml file:
Code:
<?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" package="com.xyz.fwk.persistence.hibernate.impl.bug.demo.test">
<class name="Trade" table="trade" batch-size="64" lazy="false">
<id name="id" type="int" access="field">
<generator class="native"></generator>
</id>
<component name="tradeId" class="TypeIdentifier">
<property name="id" column="TRADE_ID"/>
<property name="type" column="TRADE_ID_TYPE"/>
</component>
</class>
</hibernate-mapping>
My class definition for Trade is:
Code:
@Audited (this doesn't matter)
public class Trade implements Serializable {
protected int id;
protected ITypeIdentifier tradeId ;
public Trade() { }
public ITypeIdentifier getTradeId() { return tradeId; }
public void setTradeId(ITypeIdentifier i) { tradeId =i ; }
}
Since the getTradeId returns and ITypeIdentifier which is an interface, (hence has no super class) the method addPropertiesFromClass(XClass clazz) in org.hibernate.envers.configuration.metadata.reader.AuditedPropertiesReader
when trying to analyze ITypeIdentifier fails because the interface has no super class !
Code:
private void addPropertiesFromClass(XClass clazz) {
XClass superclazz = clazz.getSuperclass();
(super class will be null for an interface return type )
if (!"java.lang.Object".equals(superclazz.getName())) {
addPropertiesFromClass(superclazz);
}
addFromProperties(clazz.getDeclaredProperties("field"), "field", fieldAccessedPersistentProperties);
addFromProperties(clazz.getDeclaredProperties("property"), "property", propertyAccessedPersistentProperties);
}
--
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, 10 months