Spring MVC Hibernate + SQLite不创建数据库

时间:2016-04-22 10:29:45

标签: hibernate sqlite spring-mvc java-ee

我正在使用Spring MVC,Hibernate和SQLite,当我运行服务器时,每件事情都工作但数据库没有创建,也没有例外。当我从java类启动<?php function getbrands() { global $con; $fetch_brand="SELECT * FROM brands"; $run=mysqli_query($con,$fetch_brand); while($row=mysqli_fetch_array($run)); $brands_id=$row[0]; $brands_title=$row[1]; echo "<h4 align='center' style='margin:0px'> <a href='ecommerce.php?brands=$brands_id'>$brands_title</a></h4><hr>"; } ?> 时,它会创建dataBase

persistence.xml

这是public static void main(String[] args) throws Exception { ApplicationContext context = new ClassPathXmlApplicationContext( "/META-INF/persistence-config.xml"); String[] names = context.getBeanDefinitionNames(); System.out.println(context.getBeanDefinitionCount()); for (String name : names) { System.out.println("name Bean == " + context.getBean(name).getClass()); } }

persistence.xml

这是<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:util="http://www.springframework.org/schema/util" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <!-- Load database property file --> <tx:annotation-driven transaction-manager="transactionManager" /> <context:annotation-config /> <!-- Tell Spring where to scan for components --> <context:component-scan base-package="com.binov" /> <context:component-scan base-package="org.hibernate" /> <!-- Create datasource bean --> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="org.sqlite.JDBC" /> <property name="url" value="jdbc:sqlite:franchise.db" /> <property name="username" value="" /> <property name="password" value="" /> </bean> <!-- Create Entity manager - JPA --> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="packagesToScan" value="com.binov.franchise.*" /> <property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" /> </property> <!-- <property name="persistenceProvider"> <bean class="org.hibernate.jpa.HibernatePersistenceProvider" /> </property> --> <property name="jpaProperties"> <props> <prop key="hibernate.hbm2ddl.auto">create</prop> <prop key="hibernate.dialect">org.hibernate.dialect.SQLiteDialect</prop> <prop key="hibernate.show_sql">true</prop> </props> </property> </bean> <tx:annotation-driven /> <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory" /> </bean> <tx:annotation-driven transaction-manager="transactionManager"/> <tx:annotation-driven /> </beans>

SQLiteDialect

1 个答案:

答案 0 :(得分:0)

您是否尝试在JDBC URL属性中放置绝对URL(具有W / R权限)?

例如:

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

检查数据库是否在正确的路径上创建(C:/franchise.db)。