[Hibernate-JIRA] Created: (HHH-2220) session.createSQLQuery(sql) translates database type CHAR(n) to Java type char instead of String
by Regis Pires Magalhaes (JIRA)
session.createSQLQuery(sql) translates database type CHAR(n) to Java type char instead of String
------------------------------------------------------------------------------------------------
Key: HHH-2220
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2220
Project: Hibernate3
Type: Bug
Components: query-sql
Versions: 3.2.0.ga
Reporter: Regis Pires Magalhaes
createSQLQuery() method translates database type CHAR(n) to Java type char instead of String when using setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP).
That happens when I do not use addScalar(). And that is the only problem that I have found when not filling return types in advance.
A workaround I have made is to concatenate the projected field with an empty string (''). See example below:
...
query.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
String sqlQuery = "select s.name state from state s where s.name='PI' ";
query = session.createSQLQuery(sqlQuery);
...
result: [{STATE=P}]
name field is CHAR(2) in database definition (PostgreSQL, HSQLDB and Oracle were tested).
Note that it works when I concatenate the field used in projection with an empty string:
...
String sqlQuery = "select s.name || '' state from state s where s.name='PI' ";
...
result: [{STATE=PI}]
--
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
13 years, 2 months
[Hibernate-JIRA] Created: (HHH-2429) SQL Character Types Incorrectly mapped to Java objects
by Tyler Van Gorder (JIRA)
SQL Character Types Incorrectly mapped to Java objects
------------------------------------------------------
Key: HHH-2429
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2429
Project: Hibernate3
Type: Bug
Components: core
Versions: 3.2.1
Environment: Hibernate 3.2.1, Oracle10g
Reporter: Tyler Van Gorder
We have a work flow that allows the user to enter an arbitrary SQL statement to be executed by our application. We pass those queries through session.createSQLQuery().
We ran into a problem with String literals, which are reported by Oracle (ResultSetMetaData) to be CHAR. Reading the JDBC API, CHAR is a fixed length string. Hibernate is incorrectly mapping this to a Character field. We ended up overriding the Oracle dialect with our own as follows:
In our constructor, for a dialect that extends Oracle9iDialect:
super()
registerColumnType(Types.CHAR, "char($l)" );
registerHibernateType( Types.CHAR, Hibernate.STRING.getName() );
The HibernateType is the crucial one and we are overriding the behavior in the base "Dialect" class, so this appears that it would be a problem for all database variants that don't explicitly change this.
Thanks.
--
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
13 years, 2 months
[Hibernate-JIRA] Created: (EJB-276) Support for CLOB not working for DB2 when table per concrete class is being used
by breako (JIRA)
Support for CLOB not working for DB2 when table per concrete class is being used
--------------------------------------------------------------------------------
Key: EJB-276
URL: http://opensource.atlassian.com/projects/hibernate/browse/EJB-276
Project: Hibernate Entity Manager
Type: Bug
Versions: 3.2.1
Reporter: breako
Hi,
This came up in the forums:
http://forum.hibernate.org/viewtopic.php?p=2344008#2344008
Sample code: Two Pojos
@Entity
public class Person {
private int i;
@Identity
public int getI() {
return i;
}
public void setI(int i){
this.i = i;
}
}
@Entity
public class Employee extends Person{
@Basic(fetch=FetchType.LAZY)
@Lob
public String getClobAttr() {
return clobAttr;
}
public void setClobAttr(String clobAttr) {
this.clobAttr = clobAttr;
}
}
Simple test:
public static void main (String args[]) {
Query queryImpl = em.createQuery(" from Person");
List list = queryImpl.getResultList();
}
This will generate SQL
select person0_.clobAttr as clobAttr1 from (select nullif(0,0) as clobAttr from TPerson union all select clobAttr from TEmployee) person0_
which chucks the exception:
DB2 SQL error: SQLCODE: -415, SQLSTATE: 42825, SQLERRMC: null
I think the SQL hibernate should generate should be:
select person0_.clobAttr as clobAttr1 from (select cast(null as CLOB) as clobAttr from TPerson union all select clobAttr from TEmployee) person0_
--
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
13 years, 3 months
[Hibernate-JIRA] Created: (HHH-3836) composite-element with null columns in map is ignored
by Benoit Goudreault-Emond (JIRA)
composite-element with null columns in map is ignored
-----------------------------------------------------
Key: HHH-3836
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3836
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.3.0.SP1
Environment: 3.3.0 SP1, noticed with Oracle and H2 but probably happens with all databases
Reporter: Benoit Goudreault-Emond
Attachments: patate.zip
When a composite element with all properties set to NULL is inserted in a map of the said composite element, the data gets inserted to the database but is never retreived when reloading the entity.
For instance, with an entity
@Entity
public class TestEntity {
@Id
private int id;
@CollectionOfElements
private Map<String, AccessPeriod> roleAccesses = new HashMap<String, AccessPeriod>();
// boilerplate getters/setters/etc omitted
}
And AccessPeriod being
@Embeddable
public class AccessPeriod {
public Date startDate;
public Date endDate;
}
If you insert in the map an AccessPeriod with both startDate and endDate set to null and persist the TestEntity,
an entry is inserted in the auxiliary table, but when getting the TestEntity back, the map is empty.
You get the same problem with a mapping file.
This used to work in Hibernate 2.1--I found this out while porting some code to 3.3.
See the attached example. You'll need to include Hibernate and h2 (com.h2database:h2 1.0.20061217) on your classpath to run it with the given jdbc.properties, but feel free to change 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
13 years, 3 months