History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: HB-1442
Type: Improvement Improvement
Status: Closed Closed
Resolution: Won't Fix
Priority: Major Major
Assignee: Unassigned
Reporter: Rodrigo Vieira Couto
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Hibernate2

User type solves Postgres 7.x inability to handle index on 'bigint' types

Created: 18/Feb/05 07:55 AM   Updated: 18/Feb/05 04:38 PM
Component/s: core
Affects Version/s: 2.1.8
Fix Version/s: None

Original Estimate: 1 day Remaining Estimate: 1 day Time Spent: Unknown
Environment: Postgres 7.4.7, Hibernate 2.1.8, Java 1.4.2_04


 Description  « Hide
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;
}

}


 All   Comments   Work Log   Change History      Sort Order:
Gavin King - [18/Feb/05 04:38 PM ]
Great, so you are done. I'm not going to include this in the core.