欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
No Dialect mapping for JDBC type: 7
http://topic.csdn.net/u/20090304/20/d466a78e-2b2c-4623-8973-c998dda5612a.html
沒(méi)想到用SQLQUERY的時(shí)候可以有個(gè)簡(jiǎn)單的東西,就是
我看了錯誤信息有很多關(guān)于list的,網(wǎng)上幫你搜了一下,希望對你有所幫助。

createQuery與createSQLQuery兩者區別是:  


前者用的hql語(yǔ)句進(jìn)行查詢(xún),后者可以用sql語(yǔ)句查詢(xún)  

前者以hibernate生成的Bean為對象裝入list返回  

后者則是以對象數組進(jìn)行存儲  

所以使用createSQLQuery有時(shí)候也想以hibernate生成的Bean為對象裝入list返回,就不是很方便  

突然發(fā)現createSQLQuery有這樣一個(gè)方法可以直接轉換對象  

Query query = session.createSQLQuery(sql).addEntity(XXX.class);  

XXX 代表以hibernate生成的Bean的對象,也就是數據表映射出的Bean。  

太牛了啊.我郁悶啊.

No Dialect mapping for JDBC type: 7 
I got this error while I was working with hibernate and SQL Server. Following are the findings I came across. Hope this helps you too rectify this error. 

Following questions are relevant to understand this clearly. 

What is jdbc type 7? 
java.sql.Type.REAL : It is a constant in the java programming language, that identifies SQL type REAL. 
Value of this constant is 7. This is the above mentioned jdbc type 7. 

What is dialect? 
Dialect is the type of the database that hibernate is going to use. Following are the commonly used dialects. These are the subclasses of the org.hibernate.dialect.Dialect for specific databases. 

org.hibernate.dialect.HSQLDialect 
org.hibernate.dialect.Oracle9Dialect 
org.hibernate.dialect.MySQLDialect 
org.hibernate.dialect.SQLServerDialect 
org.hibernate.dialect.FirebirdDialect 
What cause this error to occur? 
The database may contain a table with field of datatype real. Hibernate dialect SQLServerDialect doesnot understand this type. So we need to explicitly convert this real type to one that dialect can understand. One way to achieve this is to write a subclass of org.hibernate.dialect.SQLServerDialect. 


package co.nr.javaalert.hibernate.dialect; 
import java.sql.Types; 
public class SubSQLServerDialect extends org.hibernate.dialect.SQLServerDialect{ 
public SQLServerDialectForBilling() { 
super(); 
registerColumnType(Types.REAL,"number($p,$s)"); 
registerHibernateType(Types.REAL,"double"); 
} 
} 

registerColumnType() method register a type name for a given type code. This step register sql column data type NUMBER(precision,scale) to Types.REAL. Then register this Types.REAL with a data type that can understand hibernate. The recommended Java mapping for the sql REAL type is as a Java float. 

Use this subclass instead of org.hibernate.dialect.SQLServerDialect in hibernate.cfg.xml. 

Reference 
SQL dialects reference/Data structure definition/Data types/Numeric types 

Hibernate 數據庫連接及SQLDialect 錯誤: No Dialect mapping for JDBC type

時(shí)間:2010-01-22 14:19 點(diǎn)擊:1235次 字體:[  ]
Hibernate 不同數據庫的連接及SQL方言

 

<!--MySql 驅動(dòng)程序 eg. mysql-connector-java-5.0.4-bin.jar-->
  <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
  <property name="connection.driver_class">com.mysql.jdbc.Driver</property>

  <!-- JDBC URL -->
  <property name="connection.url">jdbc:mysql://localhost/dbname?characterEncoding=gb2312</property>

  <!-- 數據庫用戶(hù)名-->
  <property name="connection.username">root</property>

  <!-- 數據庫密碼-->
  <property name="connection.password">root</property>
  
  
  <!--Sql Server 驅動(dòng)程序 eg. jtds-1.2.jar-->
  <property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
  <property name="connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property>

  <!-- JDBC URL -->
  <property name="connection.url">jdbc:jtds:sqlserver://localhost:1433;DatabaseName=dbname</property>

  <!-- 數據庫用戶(hù)名-->
  <property name="connection.username">sa</property>

  <!-- 數據庫密碼-->
  <property name="connection.password"></property>

  
  
  <!--Oracle 驅動(dòng)程序 ojdbc14.jar-->
  <property name="dialect">org.hibernate.dialect.OracleDialect</property>
  <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>

  <!-- JDBC URL -->
  <property name="connection.url">jdbc:oracle:thin:@localhost:1521:dbname</property>

  <!-- 數據庫用戶(hù)名-->
  <property name="connection.username">test</property>

  <!-- 數據庫密碼-->
  <property name="connection.password">test</property>



如果出現如下錯誤,則可能是Hibernate SQL方言 (hibernate.dialect)設置不正確。
Caused by: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]'last_insert_id' 不是可以識別的 函數名。

RDBMS方言
DB2org.hibernate.dialect.DB2Dialect
DB2 AS/400org.hibernate.dialect.DB2400Dialect
DB2 OS390org.hibernate.dialect.DB2390Dialect
PostgreSQLorg.hibernate.dialect.PostgreSQLDialect
MySQLorg.hibernate.dialect.MySQLDialect
MySQL with InnoDBorg.hibernate.dialect.MySQLInnoDBDialect
MySQL with MyISAMorg.hibernate.dialect.MySQLMyISAMDialect
Oracle (any version)org.hibernate.dialect.OracleDialect
Oracle 9i/10gorg.hibernate.dialect.Oracle9Dialect
Sybaseorg.hibernate.dialect.SybaseDialect
Sybase Anywhereorg.hibernate.dialect.SybaseAnywhereDialect
Microsoft SQL Serverorg.hibernate.dialect.SQLServerDialect
SAP DBorg.hibernate.dialect.SAPDBDialect
Informixorg.hibernate.dialect.InformixDialect
HypersonicSQLorg.hibernate.dialect.HSQLDialect
Ingresorg.hibernate.dialect.IngresDialect
Progressorg.hibernate.dialect.ProgressDialect
Mckoi SQLorg.hibernate.dialect.MckoiDialect
Interbaseorg.hibernate.dialect.InterbaseDialect
Pointbaseorg.hibernate.dialect.PointbaseDialect
FrontBaseorg.hibernate.dialect.FrontbaseDialect
Firebirdorg.hibernate.dialect.FirebirdDialect
以上是轉載來(lái)的
///////////////////////////////////////////////////////////////////////////////////////////
有時(shí)候,hibernate用原生SQL 查詢(xún),native SQL 的時(shí)候,會(huì )出現
org.hibernate.MappingException: No Dialect mapping for JDBC type: -1 ,-16,等等的錯誤
type 類(lèi)型代碼 可以看 java.sql.Types 中的定義,看源碼就可以了

那是因為 Dialect  未定義,重寫(xiě)類(lèi),把未定義的Dialect 注冊一下即可,
并且在 hibernate.cfg.xml中加入
Xml代碼
  1. <property name="hibernate.dialect">  
  2.     org.hibernate.dialect.OracleCustomDialect   
  3. </property>  


Java代碼
  1. import java.sql.Types;   
  2.   
  3. import org.hibernate.Hibernate;   
  4.   
  5. public class OracleCustomDialect extends org.hibernate.dialect.Oracle10gDialect {   
  6.   
  7.     public OracleCustomDialect() {   
  8.         super();   
  9.         registerHibernateType(Types.FLOAT, Hibernate.FLOAT.getName());   
  10.     }   
  11. }  
 
這是自己解決的折中辦法,最好還是遵循標準類(lèi)型
在hibernate中,Oracle9Dialect 方言定義有以下代碼:
Java代碼
  1. public class Oracle9Dialect extends Dialect {   
  2.   
  3.     private static final Logger log = LoggerFactory.getLogger( Oracle9Dialect.class );   
  4.   
  5.     public Oracle9Dialect() {   
  6.         super();   
  7.         log.warn( "The Oracle9Dialect dialect has been deprecated; use either Oracle9iDialect or Oracle10gDialect instead" );   
  8.         registerColumnType( Types.BIT, "number(1,0)" );   
  9.         registerColumnType( Types.BIGINT, "number(19,0)" );   
  10.         registerColumnType( Types.SMALLINT, "number(5,0)" );   
  11.         registerColumnType( Types.TINYINT, "number(3,0)" );   
  12.         registerColumnType( Types.INTEGER, "number(10,0)" );   
  13.         registerColumnType( Types.CHAR, "char(1 char)" );   
  14.         registerColumnType( Types.VARCHAR, 4000"varchar2($l char)" );   
  15.         registerColumnType( Types.VARCHAR, "long" );   
  16.         registerColumnType( Types.FLOAT, "float" );   
  17.         registerColumnType( Types.DOUBLE, "double precision" );   
  18.         registerColumnType( Types.DATE, "date" );   
  19.         registerColumnType( Types.TIME, "date" );   
  20.         registerColumnType( Types.TIMESTAMP, "timestamp" );   
  21.         registerColumnType( Types.VARBINARY, 2000"raw($l)" );   
  22.         registerColumnType( Types.VARBINARY, "long raw" );   
  23.         registerColumnType( Types.NUMERIC, "number($p,$s)" );   
  24.         registerColumnType( Types.DECIMAL, "number($p,$s)" );   
  25.         registerColumnType( Types.BLOB, "blob" );   
  26.         registerColumnType( Types.CLOB, "clob" );   
  27.   
  28. ……   
  29. ……  
 
而hibernate 3.3.2中 帶的Oracle10gDialect方言代碼如下,是繼承了 Oracle9Dialect
Java代碼
  1. public class Oracle10gDialect extends Oracle9iDialect {   
  2.   
  3.     public Oracle10gDialect() {   
  4.         super();   
  5.     }   
  6.   
  7.     public JoinFragment createOuterJoinFragment() {   
  8.         return new ANSIJoinFragment();   
  9.     }   
  10. }  
 
同時(shí),在public abstract class Dialect 類(lèi)中,定義了以下registerHibernateType, 所有的數據庫類(lèi)型的Dialect都是 extends Dialect
Java代碼
  1. protected Dialect() {   
  2.     log.info( "Using dialect: " + this );   
  3.     sqlFunctions.putAll( STANDARD_AGGREGATE_FUNCTIONS );   
  4.   
  5.     // standard sql92 functions (can be overridden by subclasses)   
  6.     registerFunction( "substring"new SQLFunctionTemplate( Hibernate.STRING, "substring(?1, ?2, ?3)" ) );   
  7.     registerFunction( "locate"new SQLFunctionTemplate( Hibernate.INTEGER, "locate(?1, ?2, ?3)" ) );   
  8.     registerFunction( "trim"new SQLFunctionTemplate( Hibernate.STRING, "trim(?1 ?2 ?3 ?4)" ) );   
  9.     registerFunction( "length"new StandardSQLFunction( "length", Hibernate.INTEGER ) );   
  10.     registerFunction( "bit_length"new StandardSQLFunction( "bit_length", Hibernate.INTEGER ) );   
  11.     registerFunction( "coalesce"new StandardSQLFunction( "coalesce" ) );   
  12.     registerFunction( "nullif"new StandardSQLFunction( "nullif" ) );   
  13.     registerFunction( "abs"new StandardSQLFunction( "abs" ) );   
  14.     registerFunction( "mod"new StandardSQLFunction( "mod", Hibernate.INTEGER) );   
  15.     registerFunction( "sqrt"new StandardSQLFunction( "sqrt", Hibernate.DOUBLE) );   
  16.     registerFunction( "upper"new StandardSQLFunction("upper") );   
  17.     registerFunction( "lower"new StandardSQLFunction("lower") );   
  18.     registerFunction( "cast"new CastFunction() );   
  19.     registerFunction( "extract"new SQLFunctionTemplate(Hibernate.INTEGER, "extract(?1 ?2 ?3)") );   
  20.   
  21.     //map second/minute/hour/day/month/year to ANSI extract(), override on subclasses   
  22.     registerFunction( "second"new SQLFunctionTemplate(Hibernate.INTEGER, "extract(second from ?1)") );   
  23.     registerFunction( "minute"new SQLFunctionTemplate(Hibernate.INTEGER, "extract(minute from ?1)") );   
  24.     registerFunction( "hour"new SQLFunctionTemplate(Hibernate.INTEGER, "extract(hour from ?1)") );   
  25.     registerFunction( "day"new SQLFunctionTemplate(Hibernate.INTEGER, "extract(day from ?1)") );   
  26.     registerFunction( "month"new SQLFunctionTemplate(Hibernate.INTEGER, "extract(month from ?1)") );   
  27.     registerFunction( "year"new SQLFunctionTemplate(Hibernate.INTEGER, "extract(year from ?1)") );   
  28.   
  29.     registerFunction( "str"new SQLFunctionTemplate(Hibernate.STRING, "cast(?1 as char)") );   
  30.   
  31.        // register hibernate types for default use in scalar sqlquery type auto detection   
  32.     registerHibernateType( Types.BIGINT, Hibernate.BIG_INTEGER.getName() );   
  33.     registerHibernateType( Types.BINARY, Hibernate.BINARY.getName() );   
  34.     registerHibernateType( Types.BIT, Hibernate.BOOLEAN.getName() );   
  35.     registerHibernateType( Types.CHAR, Hibernate.CHARACTER.getName() );   
  36.     registerHibernateType( Types.DATE, Hibernate.DATE.getName() );   
  37.     registerHibernateType( Types.DOUBLE, Hibernate.DOUBLE.getName() );   
  38.     registerHibernateType( Types.FLOAT, Hibernate.FLOAT.getName() );   
  39.     registerHibernateType( Types.INTEGER, Hibernate.INTEGER.getName() );   
  40.     registerHibernateType( Types.SMALLINT, Hibernate.SHORT.getName() );   
  41.     registerHibernateType( Types.TINYINT, Hibernate.BYTE.getName() );   
  42.     registerHibernateType( Types.TIME, Hibernate.TIME.getName() );   
  43.     registerHibernateType( Types.TIMESTAMP, Hibernate.TIMESTAMP.getName() );   
  44.     registerHibernateType( Types.VARCHAR, Hibernate.STRING.getName() );   
  45.     registerHibernateType( Types.VARBINARY, Hibernate.BINARY.getName() );   
  46.     registerHibernateType( Types.NUMERIC, Hibernate.BIG_DECIMAL.getName() );   
  47.     registerHibernateType( Types.DECIMAL, Hibernate.BIG_DECIMAL.getName() );   
  48.     registerHibernateType( Types.BLOB, Hibernate.BLOB.getName() );   
  49.     registerHibernateType( Types.CLOB, Hibernate.CLOB.getName() );   
  50.     registerHibernateType( Types.REAL, Hibernate.FLOAT.getName() );  
 
如果有特殊類(lèi)型確實(shí)需要,只能自定義。
所以oracle的類(lèi)型定義最好遵循以上的 java.sql.Types,
在hibernate.cfg.xml中使用 org.hibernate.dialect.OracleCustomDialect
以防出現No Dialect mapping for JDBC type錯誤
其他的 數據庫類(lèi)型,SQL SERVER  DB2 MYSQL 等等,都可以查看 hibernate的相關(guān)源碼找出個(gè)所以然來(lái)
本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
Hibernate使用jdbc只能獲取單字符問(wèn)題
Hibernate4之配置詳解
No CurrentSessionContext configured!" 異常解決方案 - esffor - JavaEye技術(shù)網(wǎng)站
【Hibernate總結系列】hibernate.cfg.xml配置 - 阿蜜果 - Bl...
Hibernate的配置文件
Hibernate 不同數據庫的連接及SQL方言
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久