[Hibernate-JIRA] Created: (HHH-3974) Invalid SQL Generated
by andrew inden (JIRA)
Invalid SQL Generated
---------------------
Key: HHH-3974
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3974
Project: Hibernate Core
Issue Type: Bug
Components: core
Environment: Hibernate Entity Manager 3.4.0.GA provided by JBOSS 5.0.1GA, MySQL 5.0
Reporter: andrew inden
SQL generated to load one-to-many is incorrect and throws exception because where clause does not use column alias.
13:42:15,553 INFO [STDOUT] Hibernate:
/*
FROM
com.devj2ee.lt4.service.link.dto.impl.Lt4LinkDto m
where
m.code = :_code */ select
lt4linkdto0_.GUID as GUID9_,
lt4linkdto0_.SEQ_NBR as SEQ2_9_,
lt4linkdto0_.VERSION_NBR as VERSION3_9_,
lt4linkdto0_.DATE_ADDED as DATE4_9_,
lt4linkdto0_.DATE_REMOVED as DATE5_9_,
lt4linkdto0_.CODE as CODE9_,
lt4linkdto0_.URL as URL9_
from
lt4.link lt4linkdto0_
where
lt4linkdto0_.CODE=? limit ?
13:42:15,757 INFO [STDOUT] Hibernate:
/* load one-to-many com.devj2ee.lt4.service.link.dto.impl.Lt4LinkDto.analyticEntries */ select
analyticen0_.LINK_GUID as LINK8_1_,
analyticen0_.GUID as GUID1_,
analyticen0_.GUID as GUID9_0_,
analyticen0_.SEQ_NBR as SEQ2_9_0_,
analyticen0_.VERSION_NBR as VERSION3_9_0_,
analyticen0_.DATE_ADDED as DATE4_9_0_,
analyticen0_.DATE_REMOVED as DATE5_9_0_,
analyticen0_.CODE as CODE9_0_,
analyticen0_.URL as URL9_0_
from
lt4.link analyticen0_
where
analyticen0_.LINK_GUID=?
--
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, 3 months
[Hibernate-JIRA] Commented: (HHH-1169) HiLoGenerator uses ints even if the id is a long
by Tim Stavenger (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1169?page=c... ]
Tim Stavenger commented on HHH-1169:
------------------------------------
While it may be acceptable to use an integer for the high value in a hi/lo algorithm, I thought part of the purpose for the org.hibernate.id.TableGenerator and org.hibernate.id.enhanced.TableGenerator classes was to be a super class for other IdentifierGenerators?
If that is the case, I would expect that these classes should really return Long instead of Integer, and use the getLong()/setLong() methods as Rich posted. That way sub classes can work with a Long and cast down if they need to rather than attempting to cast up like they would have to now.
I've already run into the same problem. I was hoping to subclass one of these classes and specialize it for my ID generation needs. However, since both return Integer instead of Long, I've had to basically copy/paste them into my class and then modify the code to return Long so that I don't lose the full range of numbers available for my IDs.
> HiLoGenerator uses ints even if the id is a long
> ------------------------------------------------
>
> Key: HHH-1169
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1169
> Project: Hibernate Core
> Issue Type: Bug
> Affects Versions: 3.1 rc2
> Environment: rc2.
> Reporter: Rich MacDonald
>
> Say you're using longs for your primary keys. Looking at the TableHiLoGenerator class, the generation goes through a step in which it is converted to an int. The particular method is:
> TableGenerator.doWorkInCurrentTransaction(Connection conn, String sql)
> Within this method, we perform the select query to get the next value, then perform the update to increment the counter. However, we extract the select query resultSet with:
> result = rs.getInt(1);
> And we update the query with:
> ups.setInt( 1, result + 1 );
> ups.setInt( 2, result );
> "Casting" longs though this int step is a bug. Instead, these get/set methods should be delegated to the IdentifierGeneratorFactory class (which has a get method but would need a set).
--
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, 3 months
[Hibernate-JIRA] Created: (HHH-3970) One-to-one association must return null instead of proxy (or actual object).
by Sandeep Vaid (JIRA)
One-to-one association must return null instead of proxy (or actual object).
----------------------------------------------------------------------------
Key: HHH-3970
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3970
Project: Hibernate Core
Issue Type: Improvement
Affects Versions: 3.3.1
Reporter: Sandeep Vaid
Priority: Critical
In hibernate, presently one-to-one associations are fetched non-lazily...
I know that this is done because, hibernate requires to fire 1 sql to find whether proxy can be created or not...
and if it has to fire 1 sql, then why not to load one-to-one object itself in 1 sql instead of creating proxy of it (in 1 sql).
Consider my scenario..
Product has one-to-one with ProductBasic which has one-to-one with ProductTerm
Now i just queried for List of Products and i got say 300 product records.. (in 1 sql query)
In this case i don;t require ProductBasic and ProductTerm.... but as these are one-to-one associations, there are
compulsorily non-lazily fetched. Thus another 300 + 300 select queries are fired to get ProductBasic and ProductTerm
which is surely unacceptable as there are 600 extra sql's getting fired.. The situation may become worst if i
have many one-to-one associations in my domain tree.
I think hibernate code must be changed so that one-to-one associations should be not compulsorily non-lazily fetched....
One way i could think of it is, if user has not asked to fetch one-to-one association then instead of
loading one-to-one object (or creating proxy) simply null should be returned without firing any SQL...
Later when user asks for this one-to-one association, now fire 1 sql to get this association..
The major advantage of this approach is that if user has not asked for one-to-one association, no extra sql (unnecessary)
queries will be fired... (specially when retriving parent collection - e.q our scenario described above)..
--
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, 3 months
[Hibernate-JIRA] Created: (HHH-3969) HQL does not give proper return type for mathematical operations on custom types within an aggregation
by Evan Hecht (JIRA)
HQL does not give proper return type for mathematical operations on custom types within an aggregation
------------------------------------------------------------------------------------------------------
Key: HHH-3969
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3969
Project: Hibernate Core
Issue Type: Bug
Components: query-hql
Affects Versions: 3.3.1
Environment: Hibernate 3.3.1, MySQL Server 5.1.33
Reporter: Evan Hecht
I have a custom type that is essentially a double, and each instance of my class has an instance of that type and an integer. I'd like to sum the integer times the custom double for each instance of my class:
select sum(f.bar * f.baz) for Foo f;
However, casting the uniqueResult() of that query to Double results in: java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Double
baz uses my custom type. I've simplified my case as much as possible, all relevant info should be included below, Main and output at the bottom. Including any non-floating-point type in an expression within an aggregation query results in a Long being returned instead of a Double, even for division. Leaving the type unset within my mapping file or setting it to "double" gives correct return types/values for all my test cases.
Foo.java:
--------------------------------------------------
public class Foo {
private Long id;
private int bar;
private Double baz;
public void setId(Long id) {
this.id = id;
}
public Long getId() {
return id;
}
public void setBar(int bar) {
this.bar = bar;
}
public int getBar() {
return bar;
}
public void setBaz(Double baz) {
this.baz = baz;
}
public Double getBaz() {
return baz;
}
}
--------------------------------------------------
Classes.hbm.xml:
--------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="Foo" table="FOO">
<id name="id" column="FOO_ID" type="long"><generator class="native"/></id>
<property name="bar"/>
<property name="baz" type="DoubleUserType"/>
</class>
</hibernate-mapping>
--------------------------------------------------
DoubleUserType.java:
--------------------------------------------------
public class DoubleUserType implements UserType{
public int[] sqlTypes() { return new int[] {Types.DOUBLE}; }
public Class<Double> returnedClass() { return Double.class; }
public void nullSafeSet(PreparedStatement st, Object value, int index) throws SQLException {
if(value == null) {
st.setNull(index, Types.DOUBLE);
}
else {
st.setDouble(index, (Double)value);
}
}
public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws SQLException {
return rs.wasNull() ? null : rs.getDouble(1);
}
public boolean isMutable() { return false; }
public boolean equals(Object x, Object y) { return x == y; }
public int hashCode(Object x) { return ((Double)x).hashCode(); }
public Object assemble(Serializable cached, Object owner) { return cached; }
public Object deepCopy(Object value) { return value; }
public Serializable disassemble(Object value) { return (Serializable) value; }
public Object replace(Object original, Object target, Object owner) { return original; }
}
--------------------------------------------------
hibernate.cfg.xml:
--------------------------------------------------
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/htest</property>
<property name="hibernate.connection.username">tester</property>
<property name="hibernate.connection.password"></property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.hbm2ddl.auto">create</property>
</session-factory>
</hibernate-configuration>
--------------------------------------------------
Main.java:
--------------------------------------------------
public class Main {
static Session s;
public static void main(String[] args) {
Configuration cfg = new Configuration().configure(new File("./hibernate.cfg.xml"));
cfg.addResource("Classes.hbm.xml");
SessionFactory sessions = cfg.buildSessionFactory();
s = sessions.openSession();
Transaction tx = s.beginTransaction();
for (int i = 0; i < 3; i++) {
Foo f = new Foo();
f.setBar(i);
f.setBaz(.5);
s.save(f);
}
tx.commit();
executeQuery("select sum(f.bar) from Foo f", 3L);
executeQuery("select sum(f.baz) from Foo f", 1.5d);
executeQuery("select min(f.baz) from Foo f", .5d);
executeQuery("select max(f.baz) from Foo f", .5d);
executeQuery("select sum(f.baz * f.bar) from Foo f", 1.5d);
executeQuery("select sum(f.baz + 1) from Foo f", 4.5d);
executeQuery("select sum(f.baz + 1.0) from Foo f", 4.5d);
executeQuery("select max(f.baz + 1) from Foo f", 1.5d);
executeQuery("select max(f.baz + 1.0) from Foo f", 1.5d);
executeQuery("select max(f.baz * 1) from Foo f", .5d);
executeQuery("select max(f.baz * 1.0) from Foo f", .5d);
executeQuery("select sum(f.baz / 2) from Foo f", .75d);
executeQuery("select sum(f.baz / 2.0) from Foo f", .75d);
executeQuery("select sum(f.baz * f.baz) from Foo f", .75d);
s.close();
}
public static void executeQuery(String query, Number expected) {
Query q = s.createQuery(query);
System.out.println("\""+query+"\":");
System.out.print("\tExpected <"+expected.getClass().getSimpleName()+">: "+expected+" Got: ");
try {
Number res = expected instanceof Double ? (Double) q.uniqueResult() : (Long) q.uniqueResult();
System.out.print(res);
System.out.println();
}
catch(ClassCastException cce) {
System.out.flush();
cce.printStackTrace();
}
}
}
--------------------------------------------------
OUTPUT
--------------------------------------------------
"select sum(f.bar) from Foo f":
Expected <Long>: 3 Got: 3.0
"select sum(f.baz) from Foo f":
Expected <Double>: 1.5 Got: 1.5
"select min(f.baz) from Foo f":
Expected <Double>: 0.5 Got: 0.5
"select max(f.baz) from Foo f":
Expected <Double>: 0.5 Got: 0.5
"select sum(f.baz * f.bar) from Foo f":
Expected <Double>: 1.5 Got: java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Double
at Main.executeQuery(Main.java:50)
at Main.main(Main.java:31)
"select sum(f.baz + 1) from Foo f":
Expected <Double>: 4.5 Got: java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Double
at Main.executeQuery(Main.java:50)
at Main.main(Main.java:32)
"select sum(f.baz + 1.0) from Foo f":
Expected <Double>: 4.5 Got: 4.5
"select max(f.baz + 1) from Foo f":
Expected <Double>: 1.5 Got: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Double
at Main.executeQuery(Main.java:50)
at Main.main(Main.java:34)
"select max(f.baz + 1.0) from Foo f":
Expected <Double>: 1.5 Got: 1.5
"select max(f.baz * 1) from Foo f":
Expected <Double>: 0.5 Got: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Double
at Main.executeQuery(Main.java:50)
at Main.main(Main.java:36)
"select max(f.baz * 1.0) from Foo f":
Expected <Double>: 0.5 Got: 0.5
"select sum(f.baz / 2) from Foo f":
Expected <Double>: 0.75 Got: java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Double
at Main.executeQuery(Main.java:50)
at Main.main(Main.java:38)
"select sum(f.baz / 2.0) from Foo f":
Expected <Double>: 0.75 Got: 0.75
"select sum(f.baz * f.baz) from Foo f":
Expected <Double>: 0.75 Got: 0.75
--
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, 3 months
[Hibernate-JIRA] Created: (BVAL-165) Caused by: java.sql.BatchUpdateException: ORA-01438: value larger than specified precision allowed for this column
by mandava srinivasa rao (JIRA)
Caused by: java.sql.BatchUpdateException: ORA-01438: value larger than specified precision allowed for this column
------------------------------------------------------------------------------------------------------------------
Key: BVAL-165
URL: http://opensource.atlassian.com/projects/hibernate/browse/BVAL-165
Project: Bean Validation
Issue Type: Bug
Reporter: mandava srinivasa rao
hi,
When i am doing Junit from RAD i am getting the below exception.
Caused by: org.hibernate.exception.DataException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:77)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:253)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:92)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:87)
at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:222)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2224)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2654)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:56)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:85)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:58)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code))
at java.lang.reflect.Method.invoke(Method.java(Compiled Code))
at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:301)
at $Proxy0.flush(Unknown Source)
at com.acs.enterprise.common.base.application.dataaccess.daoimpl.EnterpriseBaseDAOImpl.createOrUpdateObject(EnterpriseBaseDAOImpl.java:151)
... 19 more
Caused by: java.sql.BatchUpdateException: ORA-01438: value larger than specified precision allowed for this column
at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:342)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10656)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
... 39 more
I checked the respective column in DB whether the numeric entered is long or not,but every thing is fine.
In the Junit i am setting about 25 child objects to parent object and then calling saveorupdate() method in hibernate.
The above exception occurs after that.
Can anybody help this out.
--
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, 3 months
[Hibernate-JIRA] Commented: (HHH-1483) MySQL5: No Dialect mapping for JDBC type: -1
by Gail Badner (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1483?page=c... ]
Gail Badner commented on HHH-1483:
----------------------------------
I've updated org.hibernate.dialect.Dialect in trunk to register Types.LONGVARCHAR and Types.LONGVARBINARY to hibernate "text" and "image", respectively for HHH-3892.
I also added some tests for selecting "image" and "text" properties using native SQL and some tests for overriding CRUD operations for entities containing an "image" or "text" property.
Lars, can you give it a try again? It should fix your issue this time.
Thanks,
Gail
> MySQL5: No Dialect mapping for JDBC type: -1
> --------------------------------------------
>
> Key: HHH-1483
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1483
> Project: Hibernate Core
> Issue Type: Bug
> Components: core
> Affects Versions: 3.1.2
> Environment: MySQL 5.0.18-nt
> Reporter: Sergey Vladimirov
> Assignee: Gail Badner
> Priority: Minor
> Attachments: hhh-1483-patch.txt
>
>
> MySQL5: No Dialect mapping for JDBC type: -1
> SELECT answpos,answer FROM votes_answers WHERE question=? ORDER BY answpos
> mysql> describe votes_answers;
> +----------+---------+------+-----+---------+-------+
> | Field | Type | Null | Key | Default | Extra |
> +----------+---------+------+-----+---------+-------+
> | question | int(11) | NO | MUL | | |
> | answpos | int(11) | NO | | | |
> | answer | text | YES | | NULL | |
> +----------+---------+------+-----+---------+-------+
> mysql> describe temp;
> +---------+---------+------+-----+---------+-------+
> | Field | Type | Null | Key | Default | Extra |
> +---------+---------+------+-----+---------+-------+
> | answpos | int(11) | NO | | 0 | |
> | answer | text | YES | | NULL | |
> +---------+---------+------+-----+---------+-------+
> Please, let me know what to add to MySQL5Dialect :)
> Will it be ok to add? :
> registerColumnType( Types.LONGVARCHAR, "text" );
--
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, 3 months
[Hibernate-JIRA] Assigned: (HHH-1483) MySQL5: No Dialect mapping for JDBC type: -1
by Gail Badner (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1483?page=c... ]
Gail Badner reassigned HHH-1483:
--------------------------------
Assignee: Gail Badner
> MySQL5: No Dialect mapping for JDBC type: -1
> --------------------------------------------
>
> Key: HHH-1483
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1483
> Project: Hibernate Core
> Issue Type: Bug
> Components: core
> Affects Versions: 3.1.2
> Environment: MySQL 5.0.18-nt
> Reporter: Sergey Vladimirov
> Assignee: Gail Badner
> Priority: Minor
> Attachments: hhh-1483-patch.txt
>
>
> MySQL5: No Dialect mapping for JDBC type: -1
> SELECT answpos,answer FROM votes_answers WHERE question=? ORDER BY answpos
> mysql> describe votes_answers;
> +----------+---------+------+-----+---------+-------+
> | Field | Type | Null | Key | Default | Extra |
> +----------+---------+------+-----+---------+-------+
> | question | int(11) | NO | MUL | | |
> | answpos | int(11) | NO | | | |
> | answer | text | YES | | NULL | |
> +----------+---------+------+-----+---------+-------+
> mysql> describe temp;
> +---------+---------+------+-----+---------+-------+
> | Field | Type | Null | Key | Default | Extra |
> +---------+---------+------+-----+---------+-------+
> | answpos | int(11) | NO | | 0 | |
> | answer | text | YES | | NULL | |
> +---------+---------+------+-----+---------+-------+
> Please, let me know what to add to MySQL5Dialect :)
> Will it be ok to add? :
> registerColumnType( Types.LONGVARCHAR, "text" );
--
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, 3 months