2016-04-19 115 views
1

我想在Spring MVC項目中使用Hibernate和SQLite,我配置了我的項目,當我在服務器上運行它時,dataBase未創建,我無法連接或使用sqlite數據庫。SpringMVC Hibernate + SQLite不創建數據庫

服務器啓動並不是一個例外,我使用Hibernate4實體管理器。

的persistence.xml

<?xml version="1.0" encoding="UTF-8"?> 
 
<beans xmlns="http://www.springframework.org/schema/beans" 
 
\t xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" 
 
\t xmlns:jee="http://www.springframework.org/schema/jee" xmlns:util="http://www.springframework.org/schema/util" 
 
\t xmlns:tx="http://www.springframework.org/schema/tx" 
 
\t xmlns:jdbc="http://www.springframework.org/schema/jdbc" 
 
\t xsi:schemaLocation="http://www.springframework.org/schema/beans 
 
\t http://www.springframework.org/schema/beans/spring-beans.xsd 
 
\t http://www.springframework.org/schema/jee 
 
\t http://www.springframework.org/schema/jee/spring-jee.xsd 
 
\t http://www.springframework.org/schema/util 
 
\t http://www.springframework.org/schema/util/spring-util.xsd 
 
\t http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd 
 
\t http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"> 
 

 
\t <!-- Load database property file --> 
 

 
\t <bean 
 
\t \t class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
 
\t \t <property name="location"> 
 
\t \t \t <value>classpath:database.properties</value> 
 
\t \t </property> 
 
\t </bean> 
 

 
\t <!-- Create datasource bean --> 
 

 
\t <bean id="dataSource" 
 
\t \t class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
 
\t \t <property name="driverClassName" value="org.sqlite.JDBC" /> 
 
\t \t <property name="url" value="jdbc:sqlite:franchise.db" /> 
 
\t \t <property name="username" value="" /> 
 
\t \t <property name="password" value="" /> 
 
\t </bean> 
 

 

 
\t <!-- Create Entity manager - JPA --> 
 

 
\t <bean id="entityManagerFactory" 
 
\t \t class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> 
 
\t \t <property name="dataSource" ref="dataSource" /> 
 
\t \t <property name="packagesToScan" value="com.binov.franchise.model.*" /> 
 

 
\t \t <property name="jpaVendorAdapter"> 
 
\t \t \t <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" /> 
 
\t \t </property> 
 

 
\t \t <property name="jpaProperties"> 
 
\t \t \t <props> 
 
\t \t \t \t <prop key="hibernate.hbm2ddl.auto">create-drop</prop> 
 
\t \t \t \t <prop key="hibernate.dialect">org.hibernate.dialect.SQLiteDialect</prop> 
 
\t \t \t \t <prop key="hibernate.show_sql">true</prop> 
 
\t \t \t </props> 
 
\t \t </property> 
 

 
\t </bean> 
 

 
    <tx:annotation-driven /> 
 

 
\t <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> 
 
\t \t <property name="entityManagerFactory" ref="entityManagerFactory" /> 
 
\t </bean> 
 

 
<tx:annotation-driven transaction-manager="transactionManager"/> 
 
\t <tx:annotation-driven /> 
 

 
</beans> \t

pom.xml 
 

 
    <?xml version="1.0" encoding="UTF-8"?> 
 
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 
    \t xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 
 
    \t <modelVersion>4.0.0</modelVersion> 
 
    \t <groupId>com.binov</groupId> 
 
    \t <artifactId>franchise</artifactId> 
 
    \t <name>ProjectFranchise</name> 
 
    \t <packaging>war</packaging> 
 
    \t <version>1.0.0-BUILD-SNAPSHOT</version> 
 
    \t <properties> 
 
    \t \t <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
 

 
    \t \t <jdk.version>1.7</jdk.version> 
 

 
    \t \t <jackson-version>1.9.13</jackson-version> 
 

 
    \t \t <org.slf4j-version>1.6.6</org.slf4j-version> 
 

 
    \t \t <!-- <iresolve-core.mysql-connector-java>5.1.14</iresolve-core.mysql-connector-java> --> 
 

 
    \t \t <iresolve-core.hibernate-entitymanager-version>3.6.0.Final</iresolve-core.hibernate-entitymanager-version> 
 

 
    \t \t <iresolve-core.hibernate-validator.version>5.1.3.Final</iresolve-core.hibernate-validator.version> 
 

 

 
    \t \t <iresolve-core.aspectj.version>1.5.4</iresolve-core.aspectj.version> 
 

 
    \t \t <iresolve-core.junit.version>4.9</iresolve-core.junit.version> 
 

 
    \t \t <iresolve-core.org.springframework.version>4.1.5.RELEASE</iresolve-core.org.springframework.version> 
 

 

 
    \t \t <iresolve-core.org.springframework-security-version>3.2.3.RELEASE</iresolve-core.org.springframework-security-version> 
 

 

 
    \t \t <iresolve-core.javassist.version>3.3</iresolve-core.javassist.version> 
 

 
    \t \t <org.tiles-version>3.0.3</org.tiles-version> 
 

 

 

 
    \t </properties> 
 

 

 
    \t <dependencies> 
 

 

 
    \t \t <!-- Logging dependencies slf4j --> 
 

 
    \t \t <dependency> 
 
    \t \t \t <groupId>org.slf4j</groupId> 
 
    \t \t \t <artifactId>slf4j-log4j12</artifactId> 
 
    \t \t \t <version>${org.slf4j-version}</version> 
 
    \t \t </dependency> 
 
    \t \t <dependency> 
 
    \t \t \t <groupId>org.slf4j</groupId> 
 
    \t \t \t <artifactId>jcl-over-slf4j</artifactId> 
 
    \t \t \t <version>${org.slf4j-version}</version> 
 
    \t \t \t <scope>runtime</scope> 
 
    \t \t </dependency> 
 

 
    \t \t <dependency> 
 
    \t \t \t <groupId>org.slf4j</groupId> 
 
    \t \t \t <artifactId>slf4j-api</artifactId> 
 
    \t \t \t <version>${org.slf4j-version}</version> 
 
    \t \t </dependency> 
 

 
    \t \t <dependency> 
 
    \t \t \t <groupId>log4j</groupId> 
 
    \t \t \t <artifactId>log4j</artifactId> 
 
    \t \t \t <version>1.2.16</version> 
 
    \t \t \t <scope>runtime</scope> 
 
    \t \t </dependency> 
 

 

 

 
    \t \t <!-- Javassist for PROXY Solution --> 
 

 
    \t \t <dependency> 
 
    \t \t \t <groupId>javassist</groupId> 
 
    \t \t \t <artifactId>javassist</artifactId> 
 
    \t \t \t <version>${iresolve-core.javassist.version}</version> 
 
    \t \t </dependency> 
 

 
    \t \t <!-- image decode --> 
 
    \t \t <dependency> 
 
    \t \t \t <groupId>commons-codec</groupId> 
 
    \t \t \t <artifactId>commons-codec</artifactId> 
 
    \t \t \t <version>1.9</version> 
 
    \t \t </dependency> 
 

 
    \t \t <!-- Hibernate --> 
 
    \t \t 
 

 
    \t \t <dependency> 
 
    \t \t \t <groupId>org.hibernate</groupId> 
 
    \t \t \t <artifactId>hibernate-core</artifactId> 
 
    \t \t \t <version>${iresolve-core.hibernate-entitymanager-version}</version> 
 
    \t \t \t <exclusions> 
 
    \t \t \t \t <exclusion> 
 
    \t \t \t \t \t <artifactId>javassist</artifactId> 
 
    \t \t \t \t \t <groupId>org.javassist</groupId> 
 
    \t \t \t \t </exclusion> 
 
    \t \t \t </exclusions> 
 
    \t \t </dependency> 
 
    \t \t <dependency> 
 
    \t \t \t <groupId>org.hibernate</groupId> 
 
    \t \t \t <artifactId>hibernate-entitymanager</artifactId> 
 
    \t \t \t <version>${iresolve-core.hibernate-entitymanager-version}</version> 
 
    \t \t \t <exclusions> 
 
    \t \t \t \t <exclusion> 
 
    \t \t \t \t \t <groupId>asm</groupId> 
 
    \t \t \t \t \t <artifactId>asm</artifactId> 
 
    \t \t \t \t </exclusion> 
 
    \t \t \t \t <exclusion> 
 
    \t \t \t \t \t <groupId>asm</groupId> 
 
    \t \t \t \t \t <artifactId>asm-attrs</artifactId> 
 
    \t \t \t \t </exclusion> 
 
    \t \t \t \t <exclusion> 
 
    \t \t \t \t \t <groupId>cglib</groupId> 
 
    \t \t \t \t \t <artifactId>cglib</artifactId> 
 
    \t \t \t \t </exclusion> 
 
    \t \t \t \t <exclusion> 
 
    \t \t \t \t \t <artifactId>javassist</artifactId> 
 
    \t \t \t \t \t <groupId>javassist</groupId> 
 
    \t \t \t \t </exclusion> 
 
    \t \t \t \t <exclusion> 
 
    \t \t \t \t \t <groupId>org.hibernate</groupId> 
 
    \t \t \t \t \t <artifactId>hibernate-core</artifactId> 
 
    \t \t \t \t </exclusion> 
 

 
    \t \t \t </exclusions> 
 
    \t \t </dependency> 
 
    \t \t 
 
    \t \t <!-- Dependencies for Hibernate and ORM --> \t \t 
 
    \t \t <dependency> 
 
    \t \t \t <groupId>com.h2database</groupId> 
 
    \t \t \t <artifactId>h2</artifactId> 
 
    \t \t  <version>1.3.156</version> 
 
    \t \t </dependency> 
 
    \t 
 

 
    \t \t <!-- Dependencies for SQLite --> 
 
    \t \t <dependency> 
 
    \t \t \t <groupId>org.xerial</groupId> 
 
    \t \t \t <artifactId>sqlite-jdbc</artifactId> 
 
    \t \t \t <version>3.8.11.2</version> 
 
    \t \t </dependency> 
 
    \t \t <!-- <dependency> 
 
    \t \t \t <groupId>net.kemitix</groupId> 
 
    \t \t \t <artifactId>sqlite-dialect</artifactId> 
 
    \t \t \t <version>0.1.0</version> 
 
    \t \t </dependency> --> \t 
 
      
 
      <!-- SQLite JDBC library 
 
      <dependency> 
 
       <groupId>org.xerial</groupId> 
 
       <artifactId>sqlite-jdbc</artifactId> 
 
       <version>3.8.11.2</version> 
 
      </dependency>--> 
 

 
    \t \t <!-- JSR 303 with Hibernate Validator --> 
 

 
    \t \t <dependency> 
 
    \t \t \t <groupId>org.hibernate</groupId> 
 
    \t \t \t <artifactId>hibernate-validator</artifactId> 
 
    \t \t \t <version>${iresolve-core.hibernate-validator.version}</version> 
 

 
    \t \t </dependency> 
 
    \t \t <!-- Jsoooooon --> 
 
    \t \t <dependency> 
 
    \t \t \t <groupId>com.googlecode.json-simple</groupId> 
 
    \t \t \t <artifactId>json-simple</artifactId> 
 
    \t \t \t <version>1.1</version> 
 
    \t \t </dependency> 
 
    \t \t <dependency> 
 
    \t \t \t <groupId>org.json</groupId> 
 
    \t \t \t <artifactId>json</artifactId> 
 
    \t \t \t <version>20150729</version> 
 
    \t \t </dependency> 
 

 

 
    \t \t <!-- **************************** Spring ***************************************** --> 
 

 
    \t \t <dependency> 
 
    \t \t \t <groupId>org.springframework</groupId> 
 
    \t \t \t <artifactId>spring-beans</artifactId> 
 
    \t \t \t <version>${iresolve-core.org.springframework.version}</version> 
 
    \t \t </dependency> 
 
    \t \t <dependency> 
 
    \t \t \t <groupId>org.springframework</groupId> 
 
    \t \t \t <artifactId>spring-context</artifactId> 
 
    \t \t \t <version>${iresolve-core.org.springframework.version}</version> 
 
    \t \t </dependency> 
 
    \t \t <dependency> 
 
    \t \t \t <groupId>org.springframework</groupId> 
 
    \t \t \t <artifactId>spring-core</artifactId> 
 
    \t \t \t <version>${iresolve-core.org.springframework.version}</version> 
 

 

 
    \t \t \t <exclusions> 
 
    \t \t \t \t <exclusion> 
 
    \t \t \t \t \t <groupId>commons-logging</groupId> 
 
    \t \t \t \t \t <artifactId>commons-logging</artifactId> 
 
    \t \t \t \t </exclusion> 
 
    \t \t \t </exclusions> 
 

 

 
    \t \t </dependency> 
 
    \t \t <dependency> 
 
    \t \t \t <groupId>org.springframework</groupId> 
 
    \t \t \t <artifactId>spring-expression</artifactId> 
 
    \t \t \t <version>${iresolve-core.org.springframework.version}</version> 
 
    \t \t </dependency> 
 
    \t \t <dependency> 
 
    \t \t \t <groupId>org.springframework</groupId> 
 
    \t \t \t <artifactId>spring-orm</artifactId> 
 
    \t \t \t <version>${iresolve-core.org.springframework.version}</version> 
 
    \t \t </dependency> 
 
    \t \t <dependency> 
 
    \t \t \t <groupId>org.springframework</groupId> 
 
    \t \t \t <artifactId>spring-web</artifactId> 
 
    \t \t \t <version>${iresolve-core.org.springframework.version}</version> 
 
    \t \t </dependency> 
 

 

 
    \t \t <dependency> 
 
    \t \t \t <groupId>org.springframework</groupId> 
 
    \t \t \t <artifactId>spring-webmvc</artifactId> 
 
    \t \t \t <version>${iresolve-core.org.springframework.version}</version> 
 
    \t \t </dependency> 
 
    \t \t <!-- postgres connector 
 
    \t \t <dependency> 
 
    \t \t \t <groupId>org.postgresql</groupId> 
 
    \t \t \t <artifactId>postgresql</artifactId> 
 
    \t \t \t <version>9.4-1200-jdbc41</version> 
 
    \t \t </dependency>--> 
 

 
    \t \t <!-- Spring Security --> 
 

 

 
    \t \t <dependency> 
 
    \t \t \t <groupId>org.springframework.security</groupId> 
 
    \t \t \t <artifactId>spring-security-core</artifactId> 
 
    \t \t \t <version>${iresolve-core.org.springframework-security-version}</version> 
 
    \t \t \t <exclusions> 
 
    \t \t \t \t <exclusion> 
 
    \t \t \t \t \t <artifactId>spring-tx</artifactId> 
 
    \t \t \t \t \t <groupId>org.springframework</groupId> 
 
    \t \t \t \t </exclusion> 
 
    \t \t \t </exclusions> 
 
    \t \t </dependency> 
 

 
    \t \t <dependency> 
 
    \t \t \t <groupId>org.springframework.security</groupId> 
 
    \t \t \t <artifactId>spring-security-web</artifactId> 
 
    \t \t \t <version>${iresolve-core.org.springframework-security-version}</version> 
 
    \t \t \t <exclusions> 
 
    \t \t \t \t <exclusion> 
 
    \t \t \t \t \t <artifactId>spring-tx</artifactId> 
 
    \t \t \t \t \t <groupId>org.springframework</groupId> 
 
    \t \t \t \t </exclusion> 
 
    \t \t \t </exclusions> 
 
    \t \t </dependency> 
 

 
    \t \t <dependency> 
 
    \t \t \t <groupId>org.springframework.security</groupId> 
 
    \t \t \t <artifactId>spring-security-config</artifactId> 
 
    \t \t \t <version>${iresolve-core.org.springframework-security-version}</version> 
 
    \t \t </dependency> 
 

 
    \t \t <dependency> 
 
    \t \t \t <groupId>org.springframework.security</groupId> 
 
    \t \t \t <artifactId>spring-security-taglibs</artifactId> 
 
    \t \t \t <version>${iresolve-core.org.springframework-security-version}</version> 
 
    \t \t \t <exclusions> 
 
    \t \t \t \t <exclusion> 
 
    \t \t \t \t \t <artifactId>spring-tx</artifactId> 
 
    \t \t \t \t \t <groupId>org.springframework</groupId> 
 
    \t \t \t \t </exclusion> 
 
    \t \t \t </exclusions> 
 
    \t \t </dependency> 
 

 

 

 

 
    \t \t <!-- AspectJ --> 
 
    \t \t <dependency> 
 
    \t \t \t <groupId>aspectj</groupId> 
 
    \t \t \t <artifactId>aspectjrt</artifactId> 
 
    \t \t \t <version>${iresolve-core.aspectj.version}</version> 
 
    \t \t </dependency> 
 
    \t \t <dependency> 
 
    \t \t \t <groupId>aspectj</groupId> 
 
    \t \t \t <artifactId>aspectjweaver</artifactId> 
 
    \t \t \t <version>${iresolve-core.aspectj.version}</version> 
 
    \t \t </dependency> 
 

 

 
    \t \t <!-- Commons utilities Dependencies --> 
 

 

 

 
    \t \t <dependency> 
 
    \t \t \t <groupId>commons-fileupload</groupId> 
 
    \t \t \t <artifactId>commons-fileupload</artifactId> 
 
    \t \t \t <version>1.2.2</version> 
 
    \t \t </dependency> 
 

 
    \t \t <dependency> 
 
    \t \t \t <groupId>commons-io</groupId> 
 
    \t \t \t <artifactId>commons-io</artifactId> 
 
    \t \t \t <version>2.0.1</version> 
 
    \t \t </dependency> 
 

 
    \t \t <dependency> 
 
    \t \t \t <groupId>commons-collections</groupId> 
 
    \t \t \t <artifactId>commons-collections</artifactId> 
 
    \t \t \t <version>3.2.1</version> 
 
    \t \t </dependency> 
 

 
    \t \t <dependency> 
 
    \t \t \t <groupId>commons-validator</groupId> 
 
    \t \t \t <artifactId>commons-validator</artifactId> 
 
    \t \t \t <version>1.4.0</version> 
 
    \t \t </dependency> 
 

 

 
    \t \t <dependency> 
 
    \t \t \t <groupId>org.apache.commons</groupId> 
 
    \t \t \t <artifactId>commons-lang3</artifactId> 
 
    \t \t \t <version>3.0</version> 
 
    \t \t </dependency> 
 

 

 

 
    \t \t <dependency> 
 
    \t \t \t <groupId>javax.annotation</groupId> 
 
    \t \t \t <artifactId>jsr250-api</artifactId> 
 
    \t \t \t <version>1.0</version> 
 
    \t \t </dependency> 
 

 

 
    \t \t <dependency> 
 
    \t \t \t <groupId>javax.transaction</groupId> 
 
    \t \t \t <artifactId>jta</artifactId> 
 
    \t \t \t <version>1.1</version> 
 
    \t \t \t <scope>provided</scope> 
 
    \t \t </dependency> 
 

 

 
    \t \t <!-- @Inject --> 
 
    \t \t <dependency> 
 
    \t \t \t <groupId>javax.inject</groupId> 
 
    \t \t \t <artifactId>javax.inject</artifactId> 
 
    \t \t \t <version>1</version> 
 
    \t \t </dependency> 
 

 

 
    \t \t <!-- Servlet --> 
 
    \t \t <dependency> 
 
    \t \t \t <groupId>javax.servlet</groupId> 
 
    \t \t \t <artifactId>servlet-api</artifactId> 
 
    \t \t \t <version>2.5</version> 
 
    \t \t \t <scope>provided</scope> 
 
    \t \t </dependency> 
 
    \t \t <dependency> 
 
    \t \t \t <groupId>javax.servlet.jsp</groupId> 
 
    \t \t \t <artifactId>jsp-api</artifactId> 
 
    \t \t \t <version>2.1</version> 
 
    \t \t \t <scope>provided</scope> 
 
    \t \t </dependency> 
 
    \t \t <dependency> 
 
    \t \t \t <groupId>javax.servlet.jsp.jstl</groupId> 
 
    \t \t \t <artifactId>jstl-api</artifactId> 
 
    \t \t \t <version>1.2</version> 
 
    \t \t </dependency> 
 

 
    \t \t <dependency> 
 
    \t \t \t <groupId>jstl</groupId> 
 
    \t \t \t <artifactId>jstl</artifactId> 
 
    \t \t \t <version>1.2</version> 
 
    \t \t </dependency> 
 

 
    \t \t <!-- Apache Tiles --> 
 

 
    \t \t <dependency> 
 
    \t \t \t <groupId>org.apache.tiles</groupId> 
 
    \t \t \t <artifactId>tiles-jsp</artifactId> 
 
    \t \t \t <version>${org.tiles-version}</version> 
 
    \t \t </dependency> 
 

 
    \t \t <!-- Jackson JSON Processor --> 
 

 

 
    \t \t <dependency> 
 
    \t \t \t <groupId>org.codehaus.jackson</groupId> 
 
    \t \t \t <artifactId>jackson-core-asl</artifactId> 
 
    \t \t \t <version>1.9.13</version> 
 
    \t \t </dependency> 
 
    \t \t <dependency> 
 
    \t \t \t <groupId>org.codehaus.jackson</groupId> 
 
    \t \t \t <artifactId>jackson-mapper-asl</artifactId> 
 
    \t \t \t <version>1.9.13</version> 
 
    \t \t </dependency> 
 

 
    \t \t <dependency> 
 
    \t \t \t <groupId>com.fasterxml.jackson.core</groupId> 
 
    \t \t \t <artifactId>jackson-databind</artifactId> 
 
    \t \t \t <version>2.4.3</version> 
 
    \t \t </dependency> 
 

 

 
    \t \t <dependency> 
 
    \t \t \t <groupId>org.springframework</groupId> 
 
    \t \t \t <artifactId>spring-context-support</artifactId> 
 
    \t \t \t <version>${iresolve-core.org.springframework.version}</version> 
 
    \t \t </dependency> 
 

 

 

 
    \t \t <dependency> 
 
    \t \t \t <groupId>junit</groupId> 
 
    \t \t \t <artifactId>junit</artifactId> 
 
    \t \t \t <version>4.4</version> 
 
    \t \t </dependency> 
 

 

 
    \t \t <dependency> 
 
    \t \t \t <groupId>org.springframework</groupId> 
 
    \t \t \t <artifactId>spring-test</artifactId> 
 
    \t \t \t <version>2.5</version> 
 
    \t \t </dependency> 
 

 
    \t \t <dependency> 
 
    \t \t \t <groupId>javax.mail</groupId> 
 
    \t \t \t <artifactId>mail</artifactId> 
 
    \t \t \t <version>1.4.7</version> 
 
    \t \t </dependency> 
 

 
    \t \t <!-- jsonEncoder Pom --> 
 

 
    \t \t <dependency> 
 
    \t \t \t <groupId>net.sf.flexjson</groupId> 
 
    \t \t \t <artifactId>flexjson</artifactId> 
 
    \t \t \t <version>2.0</version> 
 
    \t \t </dependency> 
 
    \t </dependencies> 
 

 

 
    \t <build> 
 
    \t \t <plugins> 
 
    \t \t \t <plugin> 
 
    \t \t \t \t <artifactId>maven-eclipse-plugin</artifactId> 
 
    \t \t \t \t <version>2.9</version> 
 
    \t \t \t \t <configuration> 
 
    \t \t \t \t \t <additionalProjectnatures> 
 
    \t \t \t \t \t \t <projectnature>org.springframework.ide.eclipse.core.springnature</projectnature> 
 
    \t \t \t \t \t </additionalProjectnatures> 
 
    \t \t \t \t \t <additionalBuildcommands> 
 
    \t \t \t \t \t \t <buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand> 
 
    \t \t \t \t \t </additionalBuildcommands> 
 
    \t \t \t \t \t <downloadSources>true</downloadSources> 
 
    \t \t \t \t \t <downloadJavadocs>true</downloadJavadocs> 
 
    \t \t \t \t </configuration> 
 
    \t \t \t </plugin> 
 
    \t \t \t <plugin> 
 
    \t \t \t \t <groupId>org.apache.maven.plugins</groupId> 
 
    \t \t \t \t <artifactId>maven-compiler-plugin</artifactId> 
 
    \t \t \t \t <version>2.5.1</version> 
 
    \t \t \t \t <configuration> 
 
    \t \t \t \t \t <source>1.6</source> 
 
    \t \t \t \t \t <target>1.6</target> 
 
    \t \t \t \t \t <compilerArgument>-Xlint:all</compilerArgument> 
 
    \t \t \t \t \t <showWarnings>true</showWarnings> 
 
    \t \t \t \t \t <showDeprecation>true</showDeprecation> 
 
    \t \t \t \t </configuration> 
 
    \t \t \t </plugin> 
 
    \t \t \t <plugin> 
 
    \t \t \t \t <groupId>org.codehaus.mojo</groupId> 
 
    \t \t \t \t <artifactId>exec-maven-plugin</artifactId> 
 
    \t \t \t \t <version>1.2.1</version> 
 
    \t \t \t \t <configuration> 
 
    \t \t \t \t \t <mainClass>org.test.int1.Main</mainClass> 
 
    \t \t \t \t </configuration> 
 
    \t \t \t </plugin> 
 
    \t \t </plugins> 
 
    \t \t <finalName>${project.artifactId}</finalName> 
 
    \t </build> 
 
    </project>

SQLiteDialect.java 
 

 
    package org.hibernate.dialect; 
 

 

 

 
    import java.sql.Types; 
 

 
    import org.hibernate.dialect.function.AbstractAnsiTrimEmulationFunction; 
 
    import org.hibernate.dialect.function.NoArgSQLFunction; 
 
    import org.hibernate.dialect.function.SQLFunction; 
 
    import org.hibernate.dialect.function.SQLFunctionTemplate; 
 
    import org.hibernate.dialect.function.StandardSQLFunction; 
 
    import org.hibernate.dialect.function.VarArgsSQLFunction; 
 
    import org.hibernate.type.StandardBasicTypes; 
 

 
    public class SQLiteDialect extends Dialect { 
 
     public SQLiteDialect() { 
 
     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, "boolean"); 
 

 
     registerFunction("concat", new VarArgsSQLFunction(StandardBasicTypes.STRING, "", "||", "")); 
 
     registerFunction("mod", new SQLFunctionTemplate(StandardBasicTypes.INTEGER, "?1 % ?2")); 
 
     registerFunction("quote", new StandardSQLFunction("quote", StandardBasicTypes.STRING)); 
 
     registerFunction("random", new NoArgSQLFunction("random", StandardBasicTypes.INTEGER)); 
 
     registerFunction("round", new StandardSQLFunction("round")); 
 
     registerFunction("substr", new StandardSQLFunction("substr", StandardBasicTypes.STRING)); 
 
     registerFunction("trim", new AbstractAnsiTrimEmulationFunction() { 
 
      protected SQLFunction resolveBothSpaceTrimFunction() { 
 
       return new SQLFunctionTemplate(StandardBasicTypes.STRING, "trim(?1)"); 
 
      } 
 

 
      protected SQLFunction resolveBothSpaceTrimFromFunction() { 
 
       return new SQLFunctionTemplate(StandardBasicTypes.STRING, "trim(?2)"); 
 
      } 
 

 
      protected SQLFunction resolveLeadingSpaceTrimFunction() { 
 
       return new SQLFunctionTemplate(StandardBasicTypes.STRING, "ltrim(?1)"); 
 
      } 
 

 
      protected SQLFunction resolveTrailingSpaceTrimFunction() { 
 
       return new SQLFunctionTemplate(StandardBasicTypes.STRING, "rtrim(?1)"); 
 
      } 
 

 
      protected SQLFunction resolveBothTrimFunction() { 
 
       return new SQLFunctionTemplate(StandardBasicTypes.STRING, "trim(?1, ?2)"); 
 
      } 
 

 
      protected SQLFunction resolveLeadingTrimFunction() { 
 
       return new SQLFunctionTemplate(StandardBasicTypes.STRING, "ltrim(?1, ?2)"); 
 
      } 
 

 
      protected SQLFunction resolveTrailingTrimFunction() { 
 
       return new SQLFunctionTemplate(StandardBasicTypes.STRING, "rtrim(?1, ?2)"); 
 
      } 
 
     }); 
 
     } 
 

 
     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; 
 
     } 
 

 
     protected 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; 
 
     } 
 
    }

+1

請問任何人? –

回答

0

改變SQLite的話(比如這裏Hibernate + SQLite not creating database)後,正確地引用它:

<prop key="hibernate.dialect">com.mypackaged.dialect.SQLiteDialect</prop> 

和改變hbm2ddl.auto屬性格式爲 「更新」:

<prop key="hibernate.hbm2ddl.auto">update</prop> 

...有你試圖在您的JDBC URL屬性中放置絕對URL(具有W/R權限)?

例如:

<property name="url" value="jdbc:sqlite:c:\\franchise.db" /> (in Windows) 

檢查如果數據庫在正確的道路上創建(C:/franchise.db)。