SSH ORACLE数据库不能自动建表
[b]applicationContext.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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa.xsd ">
<!-- 扫描 @Server @Controller @Repository -->
<context:component-scan base-package="cn.itcast"/>
<!-- 加载properties文件 -->
<context:property-placeholder location="classpath:config.properties" />
<!-- 数据库连接池 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driver}" />
<property name="jdbcUrl" value="${jdbc.url}" />
<property name="user" value="${jdbc.user}" />
<property name="password" value="${jdbc.password}" />
</bean>
<!-- 整合JPA配置 -->
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="cn.itcast.bos.domain" />
<property name="persistenceProvider">
<bean class="org.hibernate.jpa.HibernatePersistenceProvider" />
</property>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<!-- 自动建表 -->
<property name="generateDdl" value="true" />
<property name="database" value="ORACLE" />
<property name="databasePlatform" value="org.hibernate.dialect.Oracle10gDialect" />
<property name="showSql" value="true" />
</bean>
</property>
<property name="jpaDialect">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
</property>
<property name="jpaPropertyMap">
<map>
<entry key="hibernate.query.substitutions" value="true 1, false 0" />
<entry key="hibernate.default_batch_fetch_size" value="16" />
<entry key="hibernate.max_fetch_depth" value="2" />
<entry key="hibernate.generate_statistics" value="true" />
<entry key="hibernate.bytecode.use_reflection_optimizer"
value="true" />
<entry key="hibernate.cache.use_second_level_cache" value="false" />
<entry key="hibernate.cache.use_query_cache" value="false" />
</map>
</property>
</bean>
<!-- JPA事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<!-- 注解管理事务 -->
<tx:annotation-driven transaction-manager="transactionManager"/>
<!-- 整合spring data jpa -->
<!-- <jpa:repositories base-package="cn.itcast.bos.dao" /> -->
</beans>
实体类如下:
package cn.itcast.bos.domain.base;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
/**
* @description:档案类,记录所有的分类信息,在子档中
*/
@Entity
@Table(name = "T_ARCHIVE")
public class Archive {
@Id
@GeneratedValue
@Column(name = "C_ID")
private Integer id; // 主键
@Column(name = "C_ARCHIVE_NUM", unique = true )
private String archiveNum;// 档案编号
@Column(name = "C_ARCHIVE_NAME")
private String archiveName; // 档案名称
@Column(name = "C_REMARK")
private String remark; // 备注
@Column(name = "C_HASCHILD")
private Integer hasChild;// 是否分级 0代表不分级 1代表分级
@Column(name = "C_OPERATING_TIME")
@Temporal(TemporalType.TIMESTAMP)
private Date operatingTime;// 操作时间
@Column(name = "C_OPERATOR")
private String operator; // 操作员
@Column(name = "C_OPERATING_COMPANY")
private String operatingCompany; // 操作单位
@OneToMany(mappedBy = "archive")
private Set<SubArchive> subArchives = new HashSet<>(); // 子档案
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getArchiveNum() {
return archiveNum;
}
public void setArchiveNum(String archiveNum) {
this.archiveNum = archiveNum;
}
public String getArchiveName() {
return archiveName;
}
public void setArchiveName(String archiveName) {
this.archiveName = archiveName;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
public Date getOperatingTime() {
return operatingTime;
}
public void setOperatingTime(Date operatingTime) {
this.operatingTime = operatingTime;
}
public String getOperator() {
return operator;
}
public void setOperator(String operator) {
this.operator = operator;
}
public Set<SubArchive> getSubArchives() {
return subArchives;
}
public void setSubArchives(Set<SubArchive> subArchives) {
this.subArchives = subArchives;
}
public String getOperatingCompany() {
return operatingCompany;
}
public void setOperatingCompany(String operatingCompany) {
this.operatingCompany = operatingCompany;
}
public Integer getHasChild() {
return hasChild;
}
public void setHasChild(Integer hasChild) {
this.hasChild = hasChild;
}
}
在STS里执行tomcat:run服务器不报错,能正常访问jsp页面。