
| Key: |
HB-1442
|
| Type: |
Improvement
|
| Status: |
Closed
|
| Resolution: |
Won't Fix
|
| Priority: |
Major
|
| Assignee: |
Unassigned
|
| Reporter: |
Rodrigo Vieira Couto
|
| Votes: |
0
|
| Watchers: |
1
|
|
If you were logged in you would be able to see more operations.
|
|
|
|
Time Tracking:
|
|
Original Estimate:
|
1 day
|
|
|
Remaining Estimate:
|
1 day
|
|
|
Time Spent:
|
Not Specified
|
|
|
|
|
Environment:
|
Postgres 7.4.7, Hibernate 2.1.8, Java 1.4.2_04
|
|
|
Postgres 7.x cannot handle index on columns with type 'bigint' (java correspondent: long) without explicit casting. It has been opened an issue with the Postgres development team about this. We have developed a hibernate user type that translates a long to a string on every query, triggering a the index code in postgres. It follows bellow:
package br.com.touchtec.hibernate.type;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.type.NullableType;
/**
* User type that solves Postgres 7.x bug related to the use of
* index on columns 'bigint'.<p>
*
* Original author: rcouto<br>
* Creation date: 24/11/2004
*
* @author $Author: rcouto $
* @version $Revision: 1.2 $
*/
public class Postgres7LongType extends NullableType {
public final static String NAME = "Postgres7LongType";
public boolean equals(Object arg0, Object arg1) throws HibernateException {
if (arg0 == null && arg1 == null) return true;
if (arg0 == null ^ arg1 == null) return false;
return arg0.equals(arg1);
}
public boolean isMutable() {
return false;
}
public Object get(ResultSet arg0, String arg1) throws HibernateException, SQLException {
long ret = arg0.getLong(arg1);
return new Long(ret);
}
public void set(PreparedStatement arg0, Object arg1, int arg2) throws HibernateException, SQLException {
arg0.setString(arg2, arg1.toString());
}
public int sqlType() {
return Types.BIGINT;
}
public String toString(Object arg0) throws HibernateException {
return arg0.toString();
}
public Object fromStringValue(String arg0) throws HibernateException {
return new Long(arg0);
}
public Object deepCopyNotNull(Object arg0) throws HibernateException {
return new Long(((Long) arg0).longValue());
}
public Class getReturnedClass() {
return Long.class;
}
public String getName() {
return Postgres7LongType.NAME;
}
public boolean hasNiceEquals() {
return true;
}
}
|
|
Description
|
Postgres 7.x cannot handle index on columns with type 'bigint' (java correspondent: long) without explicit casting. It has been opened an issue with the Postgres development team about this. We have developed a hibernate user type that translates a long to a string on every query, triggering a the index code in postgres. It follows bellow:
package br.com.touchtec.hibernate.type;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.type.NullableType;
/**
* User type that solves Postgres 7.x bug related to the use of
* index on columns 'bigint'.<p>
*
* Original author: rcouto<br>
* Creation date: 24/11/2004
*
* @author $Author: rcouto $
* @version $Revision: 1.2 $
*/
public class Postgres7LongType extends NullableType {
public final static String NAME = "Postgres7LongType";
public boolean equals(Object arg0, Object arg1) throws HibernateException {
if (arg0 == null && arg1 == null) return true;
if (arg0 == null ^ arg1 == null) return false;
return arg0.equals(arg1);
}
public boolean isMutable() {
return false;
}
public Object get(ResultSet arg0, String arg1) throws HibernateException, SQLException {
long ret = arg0.getLong(arg1);
return new Long(ret);
}
public void set(PreparedStatement arg0, Object arg1, int arg2) throws HibernateException, SQLException {
arg0.setString(arg2, arg1.toString());
}
public int sqlType() {
return Types.BIGINT;
}
public String toString(Object arg0) throws HibernateException {
return arg0.toString();
}
public Object fromStringValue(String arg0) throws HibernateException {
return new Long(arg0);
}
public Object deepCopyNotNull(Object arg0) throws HibernateException {
return new Long(((Long) arg0).longValue());
}
public Class getReturnedClass() {
return Long.class;
}
public String getName() {
return Postgres7LongType.NAME;
}
public boolean hasNiceEquals() {
return true;
}
}
|
Show » |
|