以前使用Hibernate 使用了 以下代码:
- SQLQuery SqlQuery = session.createSQLQuery(sql.toString());
- // 设置值
- SqlQuery.addScalar("contractid", Hibernate.STRING);
- // .....
SQLQuery SqlQuery = session.createSQLQuery(sql.toString());
// 设置值
SqlQuery.addScalar("contractid", Hibernate.STRING);
// .....
现在hibernate 版本升级了,就报错了,现在是下面的代替方法:
- // 用这里面的警醒代替
- StandardBasicTypes.CHARACTER_ARRAY
- StringType.INSTANCE
// 用这里面的警醒代替
StandardBasicTypes.CHARACTER_ARRAY
StringType.INSTANCE
两者区别不大,StandardBasicTypes 里面定义了全是 各种Type 的静态属性,其实是一个东西:
- public class StandardBasicTypes {
- 040 /***
- 041 * The standard Hibernate type for mapping {@link Boolean} to JDBC {@link java.sql.Types#BIT BIT}.
- 042 *
- 043 * @see BooleanType
- 044 */
- 045 public static final BooleanType BOOLEAN = BooleanType.INSTANCE;
- 046
- 047 /***
- 048 * The standard Hibernate type for mapping {@link Boolean} to JDBC {@link java.sql.Types#INTEGER INTEGER}.
- 049 *
- 050 * @see NumericBooleanType
- 051 */
- 052 public static final NumericBooleanType NUMERIC_BOOLEAN = NumericBooleanType.INSTANCE;
- 053
- 054 /***
- 055 * The standard Hibernate type for mapping {@link Boolean} to JDBC {@link java.sql.Types#CHAR CHAR(1)} (using 'T'/'F').
- 056 *
- 057 * @see TrueFalseType
- 058 */
- 059 public static final TrueFalseType TRUE_FALSE = TrueFalseType.INSTANCE;
- 060
- 061 /***
- 062 * The standard Hibernate type for mapping {@link Boolean} to JDBC {@link java.sql.Types#CHAR CHAR(1)} (using 'Y'/'N').
- 063 *
- 064 * @see YesNoType
- 065 */
- 066 public static final YesNoType YES_NO = YesNoType.INSTANCE;
- 067
- 068 /***
- 069 * The standard Hibernate type for mapping {@link Byte} to JDBC {@link java.sql.Types#TINYINT TINYINT}.
- 070 */
- 071 public static final ByteType BYTE = ByteType.INSTANCE;
- 。
- 。
- 。
- }
public class StandardBasicTypes {
040 /***
041 * The standard Hibernate type for mapping {@link Boolean} to JDBC {@link java.sql.Types#BIT BIT}.
042 *
043 * @see BooleanType
044 */
045 public static final BooleanType BOOLEAN = BooleanType.INSTANCE;
046
047 /***
048 * The standard Hibernate type for mapping {@link Boolean} to JDBC {@link java.sql.Types#INTEGER INTEGER}.
049 *
050 * @see NumericBooleanType
051 */
052 public static final NumericBooleanType NUMERIC_BOOLEAN = NumericBooleanType.INSTANCE;
053
054 /***
055 * The standard Hibernate type for mapping {@link Boolean} to JDBC {@link java.sql.Types#CHAR CHAR(1)} (using 'T'/'F').
056 *
057 * @see TrueFalseType
058 */
059 public static final TrueFalseType TRUE_FALSE = TrueFalseType.INSTANCE;
060
061 /***
062 * The standard Hibernate type for mapping {@link Boolean} to JDBC {@link java.sql.Types#CHAR CHAR(1)} (using 'Y'/'N').
063 *
064 * @see YesNoType
065 */
066 public static final YesNoType YES_NO = YesNoType.INSTANCE;
067
068 /***
069 * The standard Hibernate type for mapping {@link Byte} to JDBC {@link java.sql.Types#TINYINT TINYINT}.
070 */
071 public static final ByteType BYTE = ByteType.INSTANCE;
。
。
。
}
除了有StringType.INSTANCE ,还有很多类型。在org.hibernate.type 下。个人建议还是使用 StandardBasicTypes