作用:

1.提高性能

2.指定要返回哪几个字段,为指定的不返回(主要用于select *查询全部)

3.也可指定返回字段的具体类型

常用于自定义本地sql中

如:

StringBuffer sql=new StringBuffer("select CONTENTID as \"contentid\",STATUS as \"status\" from CONTENTDETAIL where 1=1  and  TO_CHAR(PUBLISHDATE,'yyyy-mm-dd')='"+tadayTime+"'");
Session session=sessionFactory.getCurrentSession();
SQLQuery sqlQuery =session.createSQLQuery(sql.toString()).addScalar("contentid", StandardBasicTypes.LONG).addScalar("status", StandardBasicTypes.INTEGER);
sqlQuery.setResultTransformer(Transformers.aliasToBean(QtmThridPartMessageContentDetailDto.class));

最后附上

StandardBasicTypes这个类的源码,供查询
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.type; import java.util.HashSet;
import java.util.Set; import org.hibernate.type.descriptor.sql.SqlTypeDescriptor; /**
* Centralizes access to the standard set of basic {@link Type types}.
* <p/>
* Type mappings can be adjusted per {@link org.hibernate.SessionFactory}. These adjusted mappings can be accessed
* from the {@link org.hibernate.TypeHelper} instance obtained via {@link org.hibernate.SessionFactory#getTypeHelper()}
*
* @see BasicTypeRegistry
* @see org.hibernate.TypeHelper
* @see org.hibernate.SessionFactory#getTypeHelper()
*
* @author Gavin King
* @author Steve Ebersole
*/
@SuppressWarnings( {"UnusedDeclaration"})
public final class StandardBasicTypes {
private StandardBasicTypes() {
} private static final Set<SqlTypeDescriptor> SQL_TYPE_DESCRIPTORS = new HashSet<SqlTypeDescriptor>(); /**
* The standard Hibernate type for mapping {@link Boolean} to JDBC {@link java.sql.Types#BIT BIT}.
*
* @see BooleanType
*/
public static final BooleanType BOOLEAN = BooleanType.INSTANCE; /**
* The standard Hibernate type for mapping {@link Boolean} to JDBC {@link java.sql.Types#INTEGER INTEGER}.
*
* @see NumericBooleanType
*/
public static final NumericBooleanType NUMERIC_BOOLEAN = NumericBooleanType.INSTANCE; /**
* The standard Hibernate type for mapping {@link Boolean} to JDBC {@link java.sql.Types#CHAR CHAR(1)} (using 'T'/'F').
*
* @see TrueFalseType
*/
public static final TrueFalseType TRUE_FALSE = TrueFalseType.INSTANCE; /**
* The standard Hibernate type for mapping {@link Boolean} to JDBC {@link java.sql.Types#CHAR CHAR(1)} (using 'Y'/'N').
*
* @see YesNoType
*/
public static final YesNoType YES_NO = YesNoType.INSTANCE; /**
* The standard Hibernate type for mapping {@link Byte} to JDBC {@link java.sql.Types#TINYINT TINYINT}.
*/
public static final ByteType BYTE = ByteType.INSTANCE; /**
* The standard Hibernate type for mapping {@link Short} to JDBC {@link java.sql.Types#SMALLINT SMALLINT}.
*
* @see ShortType
*/
public static final ShortType SHORT = ShortType.INSTANCE; /**
* The standard Hibernate type for mapping {@link Integer} to JDBC {@link java.sql.Types#INTEGER INTEGER}.
*
* @see IntegerType
*/
public static final IntegerType INTEGER = IntegerType.INSTANCE; /**
* The standard Hibernate type for mapping {@link Long} to JDBC {@link java.sql.Types#BIGINT BIGINT}.
*
* @see LongType
*/
public static final LongType LONG = LongType.INSTANCE; /**
* The standard Hibernate type for mapping {@link Float} to JDBC {@link java.sql.Types#FLOAT FLOAT}.
*
* @see FloatType
*/
public static final FloatType FLOAT = FloatType.INSTANCE; /**
* The standard Hibernate type for mapping {@link Double} to JDBC {@link java.sql.Types#DOUBLE DOUBLE}.
*
* @see DoubleType
*/
public static final DoubleType DOUBLE = DoubleType.INSTANCE; /**
* The standard Hibernate type for mapping {@link java.math.BigInteger} to JDBC {@link java.sql.Types#NUMERIC NUMERIC}.
*
* @see BigIntegerType
*/
public static final BigIntegerType BIG_INTEGER = BigIntegerType.INSTANCE; /**
* The standard Hibernate type for mapping {@link java.math.BigDecimal} to JDBC {@link java.sql.Types#NUMERIC NUMERIC}.
*
* @see BigDecimalType
*/
public static final BigDecimalType BIG_DECIMAL = BigDecimalType.INSTANCE; /**
* The standard Hibernate type for mapping {@link Character} to JDBC {@link java.sql.Types#CHAR CHAR(1)}.
*
* @see CharacterType
*/
public static final CharacterType CHARACTER = CharacterType.INSTANCE; /**
* The standard Hibernate type for mapping {@link String} to JDBC {@link java.sql.Types#VARCHAR VARCHAR}.
*
* @see StringType
*/
public static final StringType STRING = StringType.INSTANCE; /**
* The standard Hibernate type for mapping {@link java.net.URL} to JDBC {@link java.sql.Types#VARCHAR VARCHAR}.
*
* @see UrlType
*/
public static final UrlType URL = UrlType.INSTANCE; /**
* The standard Hibernate type for mapping {@link java.util.Date} ({@link java.sql.Time}) to JDBC
* {@link java.sql.Types#TIME TIME}.
*
* @see TimeType
*/
public static final TimeType TIME = TimeType.INSTANCE; /**
* The standard Hibernate type for mapping {@link java.util.Date} ({@link java.sql.Date}) to JDBC
* {@link java.sql.Types#DATE DATE}.
*
* @see TimeType
*/
public static final DateType DATE = DateType.INSTANCE; /**
* The standard Hibernate type for mapping {@link java.util.Date} ({@link java.sql.Timestamp}) to JDBC
* {@link java.sql.Types#TIMESTAMP TIMESTAMP}.
*
* @see TimeType
*/
public static final TimestampType TIMESTAMP = TimestampType.INSTANCE; /**
* The standard Hibernate type for mapping {@link java.util.Calendar} to JDBC
* {@link java.sql.Types#TIMESTAMP TIMESTAMP}.
*
* @see CalendarType
*/
public static final CalendarType CALENDAR = CalendarType.INSTANCE; /**
* The standard Hibernate type for mapping {@link java.util.Calendar} to JDBC
* {@link java.sql.Types#DATE DATE}.
*
* @see CalendarDateType
*/
public static final CalendarDateType CALENDAR_DATE = CalendarDateType.INSTANCE; /**
* The standard Hibernate type for mapping {@link Class} to JDBC {@link java.sql.Types#VARCHAR VARCHAR}.
*
* @see ClassType
*/
public static final ClassType CLASS = ClassType.INSTANCE; /**
* The standard Hibernate type for mapping {@link java.util.Locale} to JDBC {@link java.sql.Types#VARCHAR VARCHAR}.
*
* @see LocaleType
*/
public static final LocaleType LOCALE = LocaleType.INSTANCE; /**
* The standard Hibernate type for mapping {@link java.util.Currency} to JDBC {@link java.sql.Types#VARCHAR VARCHAR}.
*
* @see CurrencyType
*/
public static final CurrencyType CURRENCY = CurrencyType.INSTANCE; /**
* The standard Hibernate type for mapping {@link java.util.TimeZone} to JDBC {@link java.sql.Types#VARCHAR VARCHAR}.
*
* @see TimeZoneType
*/
public static final TimeZoneType TIMEZONE = TimeZoneType.INSTANCE; /**
* The standard Hibernate type for mapping {@link java.util.UUID} to JDBC {@link java.sql.Types#BINARY BINARY}.
*
* @see UUIDBinaryType
*/
public static final UUIDBinaryType UUID_BINARY = UUIDBinaryType.INSTANCE; /**
* The standard Hibernate type for mapping {@link java.util.UUID} to JDBC {@link java.sql.Types#CHAR CHAR}.
*
* @see UUIDCharType
*/
public static final UUIDCharType UUID_CHAR = UUIDCharType.INSTANCE; /**
* The standard Hibernate type for mapping {@code byte[]} to JDBC {@link java.sql.Types#VARBINARY VARBINARY}.
*
* @see BinaryType
*/
public static final BinaryType BINARY = BinaryType.INSTANCE; /**
* The standard Hibernate type for mapping {@link Byte Byte[]} to JDBC {@link java.sql.Types#VARBINARY VARBINARY}.
*
* @see WrapperBinaryType
*/
public static final WrapperBinaryType WRAPPER_BINARY = WrapperBinaryType.INSTANCE; /**
* The standard Hibernate type for mapping {@code byte[]} to JDBC {@link java.sql.Types#LONGVARBINARY LONGVARBINARY}.
*
* @see ImageType
* @see #MATERIALIZED_BLOB
*/
public static final ImageType IMAGE = ImageType.INSTANCE; /**
* The standard Hibernate type for mapping {@link java.sql.Blob} to JDBC {@link java.sql.Types#BLOB BLOB}.
*
* @see BlobType
* @see #MATERIALIZED_BLOB
*/
public static final BlobType BLOB = BlobType.INSTANCE; /**
* The standard Hibernate type for mapping {@code byte[]} to JDBC {@link java.sql.Types#BLOB BLOB}.
*
* @see MaterializedBlobType
* @see #MATERIALIZED_BLOB
* @see #IMAGE
*/
public static final MaterializedBlobType MATERIALIZED_BLOB = MaterializedBlobType.INSTANCE; /**
* The standard Hibernate type for mapping {@code char[]} to JDBC {@link java.sql.Types#VARCHAR VARCHAR}.
*
* @see CharArrayType
*/
public static final CharArrayType CHAR_ARRAY = CharArrayType.INSTANCE; /**
* The standard Hibernate type for mapping {@link Character Character[]} to JDBC
* {@link java.sql.Types#VARCHAR VARCHAR}.
*
* @see CharacterArrayType
*/
public static final CharacterArrayType CHARACTER_ARRAY = CharacterArrayType.INSTANCE; /**
* The standard Hibernate type for mapping {@link String} to JDBC {@link java.sql.Types#LONGVARCHAR LONGVARCHAR}.
* <p/>
* Similar to a {@link #MATERIALIZED_CLOB}
*
* @see TextType
*/
public static final TextType TEXT = TextType.INSTANCE; /**
* The standard Hibernate type for mapping {@link String} to JDBC {@link java.sql.Types#LONGNVARCHAR LONGNVARCHAR}.
* <p/>
* Similar to a {@link #MATERIALIZED_NCLOB}
*
* @see NTextType
*/
public static final NTextType NTEXT = NTextType.INSTANCE; /**
* The standard Hibernate type for mapping {@link java.sql.Clob} to JDBC {@link java.sql.Types#CLOB CLOB}.
*
* @see ClobType
* @see #MATERIALIZED_CLOB
*/
public static final ClobType CLOB = ClobType.INSTANCE; /**
* The standard Hibernate type for mapping {@link java.sql.NClob} to JDBC {@link java.sql.Types#NCLOB NCLOB}.
*
* @see NClobType
* @see #MATERIALIZED_NCLOB
*/
public static final NClobType NCLOB = NClobType.INSTANCE; /**
* The standard Hibernate type for mapping {@link String} to JDBC {@link java.sql.Types#CLOB CLOB}.
*
* @see MaterializedClobType
* @see #MATERIALIZED_CLOB
* @see #TEXT
*/
public static final MaterializedClobType MATERIALIZED_CLOB = MaterializedClobType.INSTANCE; /**
* The standard Hibernate type for mapping {@link String} to JDBC {@link java.sql.Types#NCLOB NCLOB}.
*
* @see MaterializedNClobType
* @see #MATERIALIZED_CLOB
* @see #NTEXT
*/
public static final MaterializedNClobType MATERIALIZED_NCLOB = MaterializedNClobType.INSTANCE; /**
* The standard Hibernate type for mapping {@link java.io.Serializable} to JDBC {@link java.sql.Types#VARBINARY VARBINARY}.
* <p/>
* See especially the discussion wrt {@link ClassLoader} determination on {@link SerializableType}
*
* @see SerializableType
*/
public static final SerializableType SERIALIZABLE = SerializableType.INSTANCE;
}
												

hibernate 中addScalar的用法与作用的更多相关文章

  1. hibernate中 inverse的用法(转载)

    http://blog.csdn.net/xiaoxian8023/article/details/15380529 一.Inverse是hibernate双向关系中的基本概念.inverse的真正作 ...

  2. Hibernate中Criteria的用法

    概念 Criterion 是 Criteria 的查询条件.Criteria 提供了 add(Criterion criterion) 方法来添加查询条件. Criterion 接口的主要实现包括: ...

  3. 一口一口吃掉Hibernate(八)——Hibernate中inverse的用法

    一.Inverse是hibernate双向关系中的基本概念.inverse的真正作用就是指定由哪一方来维护之间的关联关系.当一方中指定了“inverse=false”(默认),那么那一方就有责任负责之 ...

  4. 转 Hibernate中cascade和inverse的作用

    Inverse和cascade是Hibernate映射中最难掌握的两个属性.两者都在对象的关联操作中发挥作用.1.明确inverse和cascade的作用inverse 决定是否把对对象中集合的改动反 ...

  5. Hibernate中cascade和inverse的作用

    Inverse和cascade是Hibernate映射中最难掌握的两个属性.两者都在对象的关联操作中发挥作用.1.明确inverse和cascade的作用inverse 决定是否把对对象中集合的改动反 ...

  6. Hibernate中Restrictions查询用法(转)

    Restrictions查询用法 HQL运算符 QBC运算符 含义 = Restrictions.eq() 等于equal <> Restrictions.ne() 不等于not equa ...

  7. 详解在Hibernate中配置数据库方言的作用和好处以及各种数据库的方言连接

    Hibernate底层依然使用SQL语句来执行数据库操作,虽然所有关系型数据库都支持使用标准SQL语句,但所有数据库都对标准SQL进行了一些扩展,所以在语法细节上存在一些差异,因此Hibernate需 ...

  8. hibernate中SessionFactory与Session的作用

    首先,SessionFactory是线程安全的,SessionFactory用到了工厂模式. 其创建和销毁需要耗费很大的资源,所以一个应用中的一个数据库一般只对应一个sessionfactory. S ...

  9. Python中pass的用法、作用

    pass主要作用就是占位,让代码整体完整.如果定义一个函数里面为空或一个判断写好了之后还没想好满足条件需要执行执行什么逻辑,又想留着后面使用,但是函数和判断里面为空,那么就会报错,当你还没想清楚函数内 ...

随机推荐

  1. css transition & animation

    transition 支持:IE10+ img{ transition: 1s 1s height ease; } transition-property: 属性transition-duration ...

  2. Ubuntu 16.04.2 LTS 安装 jdk1.6 和 tomcat6 (二)

    上一篇记录和分享了jdk1.6 在Ubuntu 16.04.2 环境下的安装配置,本文开始安装和配置tomcat 6     2 安装tomcat   http://tomcat.apache.org ...

  3. Jenkins 使用 Build Flow 插件配置工作流任务依赖

    Jenkins 使用 Build Flow 插件配置工作流任务依赖 Jenkins 多任务依赖方式的配置方法目前可以通过MultiJob Project 或者Build Flow 或者Piplelin ...

  4. SQL Server—— 如何创建定时作业

    在做SQL server 管理时,往往需要每日执行定时任务,但是如果每天都去人工执行,非常不方便,而且一般定时操作,都应该是在数据库压力不大时,一般是在夜间.所以我们需要创建定时作业来代替人工的执行定 ...

  5. asp.net web 应用站点支持域账户登录

    1.IIS站点应用程序池设置管道模式为classic模式,identity设置为管理员账户 2.站点验证设置,只打开windows验证,其他都关闭 3.应用程序配置web.config配置如下: &l ...

  6. PHP设计日历类一 (38)

    由两个文件组成: 第一个test.php <style> table { border:1px solid #; } .fontb { color:white; background:bl ...

  7. (转)科普:SATA、PCIe、AHCI、NVMe

    原文链接:https://forum.51nb.com/thread-1670848-1-1.html IT 界总喜欢发明新名词.而且同一个东西,可能有几个不同的名字.同一个名字,又可能指不同的东西. ...

  8. php请求远程url内容方法

    php请求远程url内容有两个方法fopen/file_get_contents和curl. 1,fopen/file_get_contents与curl的差异 (1)fopen /file_get_ ...

  9. PHP消息队列实现

    一个经典的消息队列就是这样的,主要是入队出队操作. shell脚本日志输出 学习地址:http://www.imooc.com/article/19111

  10. 3. STL编程三

    1. 算法容器的使用: #include <iostream> #include <functional> #include <vector> #include & ...