hibernate链接sqlite问题

问题描述

hibernate链接sqlite问题

 package com.free.core.dialect;

/*
 * The author disclaims copyright to this source code. In place of
 * a legal notice, here is a blessing:
 *
 * May you do good and not evil.
 * May you find forgiveness for yourself and forgive others.
 * May you share freely, never taking more than you give.
 *
 */
import java.sql.Types;

import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.function.SQLFunctionTemplate;
import org.hibernate.dialect.function.StandardSQLFunction;
import org.hibernate.dialect.function.VarArgsSQLFunction;
import org.hibernate.type.IntegerType;
import org.hibernate.type.StringType;

public class SQLiteDialect extends Dialect {
    public SQLiteDialect() {
        super();
        registerColumnType(Types.BIT, "integer");
        registerColumnType(Types.TINYINT, "tinyint");
        registerColumnType(Types.SMALLINT, "smallint");
        registerColumnType(Types.INTEGER, "integer");
        registerColumnType(Types.BIGINT, "bigint");
        registerColumnType(Types.FLOAT, "float");
        registerColumnType(Types.REAL, "real");
        registerColumnType(Types.DOUBLE, "double");
        registerColumnType(Types.NUMERIC, "numeric");
        registerColumnType(Types.DECIMAL, "decimal");
        registerColumnType(Types.CHAR, "char");
        registerColumnType(Types.VARCHAR, "varchar");
        registerColumnType(Types.LONGVARCHAR, "longvarchar");
        registerColumnType(Types.DATE, "date");
        registerColumnType(Types.TIME, "time");
        registerColumnType(Types.TIMESTAMP, "timestamp");
        registerColumnType(Types.BINARY, "blob");
        registerColumnType(Types.VARBINARY, "blob");
        registerColumnType(Types.LONGVARBINARY, "blob");
        // registerColumnType(Types.NULL, "null");
        registerColumnType(Types.BLOB, "blob");
        registerColumnType(Types.CLOB, "clob");
        registerColumnType(Types.BOOLEAN, "integer");

        registerFunction("concat", new VarArgsSQLFunction(StringType.INSTANCE, "", "||", ""));
        registerFunction("mod", new SQLFunctionTemplate(IntegerType.INSTANCE, "?1 % ?2"));
        registerFunction("substr", new StandardSQLFunction("substr", StringType.INSTANCE));
        registerFunction("substring", new StandardSQLFunction("substr", StringType.INSTANCE));
    }

    public boolean supportsIdentityColumns() {
        return true;
    }

    /*
     public boolean supportsInsertSelectIdentity() {
     return true; // As specify in NHibernate dialect
     }
     */

    public boolean hasDataTypeInIdentityColumn() {
        return false; // As specify in NHibernate dialect
    }

    /*
     public String appendIdentitySelectToInsert(String insertString) {
     return new StringBuffer(insertString.length()+30). // As specify in NHibernate dialect
     append(insertString).
     append("; ").append(getIdentitySelectString()).
     toString();
     }
     */

    public String getIdentityColumnString() {
        // return "integer primary key autoincrement";
        return "integer";
    }

    public String getIdentitySelectString() {
        return "select last_insert_rowid()";
    }

    public boolean supportsLimit() {
        return true;
    }

    public String getLimitString(String query, boolean hasOffset) {
        return new StringBuffer(query.length() + 20).append(query).append(
                hasOffset ? " limit ? offset ?" : " limit ?").toString();
    }

    public boolean supportsTemporaryTables() {
        return true;
    }

    public String getCreateTemporaryTableString() {
        return "create temporary table if not exists";
    }

    public boolean dropTemporaryTableAfterUse() {
        return false;
    }

    public boolean supportsCurrentTimestampSelection() {
        return true;
    }

    public boolean isCurrentTimestampSelectStringCallable() {
        return false;
    }

    public String getCurrentTimestampSelectString() {
        return "select current_timestamp";
    }

    public boolean supportsUnionAll() {
        return true;
    }

    public boolean hasAlterTable() {
        return false; // As specify in NHibernate dialect
    }

    public boolean dropConstraints() {
        return false;
    }

    public String getAddColumnString() {
        return "add column";
    }

    public String getForUpdateString() {
        return "";
    }

    public boolean supportsOuterJoinForUpdate() {
        return false;
    }

    public String getDropForeignKeyString() {
        throw new UnsupportedOperationException(
                "No drop foreign key syntax supported by SQLiteDialect");
    }

    public String getAddForeignKeyConstraintString(String constraintName,
            String[] foreignKey, String referencedTable, String[] primaryKey,
            boolean referencesPrimaryKey) {
        throw new UnsupportedOperationException(
                "No add foreign key syntax supported by SQLiteDialect");
    }

    public String getAddPrimaryKeyConstraintString(String constraintName) {
        throw new UnsupportedOperationException(
                "No add primary key syntax supported by SQLiteDialect");
    }

    public boolean supportsIfExistsBeforeTableName() {
        return true;
    }

    public boolean supportsCascadeDelete() {
        return false;
    }

    /**
     * 修复分页bug
     * @author Z.kc
     */
    @Override
    public boolean bindLimitParametersInReverseOrder() {
        return true;
    }
}

 <?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
    "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>

    <!-- Database connection settings -->
    <property name="connection.driver_class">org.sqlite.JDBC</property>
    <property name="connection.url">jdbc:sqlite:D:/test.db</property>
    <property name="connection.username"></property>
    <property name="connection.password"></property>

    <!-- JDBC connection pool (use the built-in) -->
    <property name="c3p0.min_size">0</property>
    <property name="c3p0.max_size">15</property>
    <property name="c3p0.timeout">1800</property>
    <!-- 当连接池耗尽时,一次获得连接数-->
    <property name="c3p0.acquire_increment">1</property>
    <property name="c3p0.max_statements">0</property>
    <!-- 当连接池连接耗尽时,客户端getConnection(),所等待的时间-->
    <property name="c3p0.idle_test_period">120</property>

    <!-- Enable Hibernate's automatic session context management -->
    <property name="current_session_context_class">thread</property>

    <!-- Configuration information -->
    <property name="dialect">com.free.core.dialect.SQLiteDialect</property>

    <!-- Disable the second-level cache  -->
    <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

    <!-- Echo all executed SQL to stdout -->
    <property name="hibernate.show_sql">true</property>

    <!-- Drop and re-create the database schema on startup -->
    <property name="hbm2ddl.auto">update</property>

    <property name="javax.persistence.validation.mode">none</property>

    <!-- Mapping entity class -->
    <mapping class="com.free.system.model.Depart" />
    <mapping class="com.free.system.model.User" />
    <mapping class="com.free.system.model.Role" />

</session-factory>
</hibernate-configuration>

解决方案

求高手解答啊。。感谢

解决方案二:

Hibernate 链接
sqlite 链接
hibernate 获取jdbc 链接问题

解决方案三:

死锁

解决方案四:

具体得分析,不知道你那里代码写错了。

解决方案五:

hbm2ddl.auto 设置为 update 时, hibernate会自动检测当前model的更新去update db表结构。

所以 当启动服务时,有可能是需要alter db表结构, 你做排除法。

  1. 检查当前model是否有更新。
  2. 设置 hbm2ddl.auto 为 none 或者 create。
  3. 停止服务,用其他sqlclient connect去链接访问db表,看是否能更新数据库表。
时间: 2024-08-04 05:32:59

hibernate链接sqlite问题的相关文章

hibernate链接数据库链接池c3p0配置

[html] view plain copy <bean id="dataSourceLocal" name="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">           <!-- 指定连接数据库的驱动-->           <property name="driverClass" value="$

hibernate+sqlite链接问题

问题描述 hibernate+sqlite链接问题 hibernate链接sqlite 项目启动时database is locked 是什么原因导致的呢?驱动包版本还是方言 或者是hibernate配置问题呢?有遇到这问题的吗?(能帮忙解答者 解决后高分酬谢) 解决方案 Hibernate 链接sqlite 链接hibernate与数据库的链接 解决方案二: Sqlite不支持并发执行写入操作

ios 用swift语言的,然后链接数据库,sqlite。

问题描述 ios 用swift语言的,然后链接数据库,sqlite. ios开发,用是swift语言.如何链接SQLite数据库.求详细代码 解决方案 iOS数据库Sqliteios SQlite操作数据库iOS中操作SQLite数据库 解决方案二: 用fmdb. http://www.tuicool.com/articles/jA3yUfj

junit-关于hibernate源链接的错误

问题描述 关于hibernate源链接的错误 我刚开始学习hibernate,然后用junit测试书上的代码的时候报:hibernate4.3.10.jar file has no source attachment错误,怎么解决啊?我已经在lib文件中添加了hibernate-core-4.3.10.final.jar包了.怎么弄啊?先谢谢大家了 解决方案 Hibernate 链接---------------------- 解决方案二: 这个问题是告诉你没有hibernate源代码,调试程序

php配置sqlite数据库开发实例

百度搜索下载SqLiteManager工具 PHP5已经绑定sqlite 1.手动添加的php的pdo的驱动扩展支持 ,在PHP.ini添加 extension=php_pdo.dll extension=php_pdo_sqlite.dll extension=php_sqlite.dll extension_dir = "C:\Program Files\Apache Group\php5\ext" 2.在C:\Program Files\Apache Group\php5\ext

小弟请教一个hibernate的问题,网站运行一段时间后就会出现这个错误。

问题描述 type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception java.lang.RuntimeException: tx.rollbacd() throw exception = org.hibernate.TransactionException: JDBC

asp.net C sqlite数据库的方法

asp教程.net C sqlite数据库教程的方法 需要一个SQLite的引擎啊,有个System.Data.SQLite,添加到项目引用之后就可以用了,给你个简单的参考:   SQLiteConnection mycon = new SQLiteConnection(@"data source=dbPerson.db3");   mycon.Open();   SQLiteCommand cmd = mycon.CreateCommand();   cmd.CommandText

关于Android连接MySQL的问题

问题描述 关于Android连接MySQL的问题 我在更改了数据库的值之后,就出现了如下的问题,目前不清楚为什么会这样.个人学安卓的时间不长,希望大神指导 解决方案 解决方案二: 关于Android 虚拟机 MySQL的问题.MySQL连接超时断开的问题 解决方案三: android天生不是链接sqlite么 解决方案四: android天生不是链接sqlite么 解决方案五: 把配置代码,链接代码贴出来,这样找不到问题 解决方案六: 一个截图能看懂问题!那还需要这么多Android开发人员干嘛

jbpm-JBPM链接Hibernate和MySql的疑难问题

问题描述 JBPM链接Hibernate和MySql的疑难问题 问题描述:最近在学JBPM,在页面上传一个zip格式文件,利用 org.jbpm.api.NewDeployment.addResourcesFromZipInputStream(ZipInputStream arg0)这个方法解析的时候就会报错.我是跟着视频学的,我直接拷视频的源码也报错.我怀疑是编码问题,因为报错信息最下面出现乱码.可我所有地方项目工程和,JSP页面,数据库都统一为U8编码.这个问题卡我两天了!!求大神解救啊!!