大家好,我遇到这个问题,将数据库连接mysql 的时候能自动生成表,换成oracle 的时候就不能自动生成表了
大家帮我看看是什么原因
oracle中的 sequence 已经创建
sql 脚本
create sequence S_ALARM_DEAL_INFO
minvalue 1
maxvalue 999999999999999999999999999
start with 1
increment by 1
cache 20
//实体类
@Entity
@Table(name = "xuan_user")
public class Users {
private int id;
private String name;
private Groups groups;
@ManyToOne (cascade={CascadeType.ALL})
@JoinColumn(name="groupnumber")
public Groups getGroups() {
return groups;
}
public void setGroups(Groups groups) {
this.groups = groups;
}
@Id
@SequenceGenerator(name = "generator_user" ,sequenceName = "generator_user",allocationSize = 1,initialValue = 0)
@GeneratedValue(strategy = GenerationType.AUTO,generator = "generator_user")
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
spring 配置文件
<bean id="mySessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="oracleSource" />
<property name="mappingLocations">
<list>
<value>classpath:/com/xuan/model/*.hbm.xml</value>
</list>
</property>
<property name="packagesToScan">
<list>
<value>com.xuan.model</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<!--
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
-->
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle9iDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
</props>
</property>
</bean>
------解决方案--------------------
有什么异常信息没?
------解决方案--------------------
报的什么错,你在映射文件里是怎么写的
------解决方案--------------------
hibernate要生成表 那么你首先要先建立数据库,他不能帮你建立的,只能正反映射过去,实现生成表.
<prop key="hibernate.hbm2ddl.auto">update</prop>
create:表存在不创建
create-drop: 表存在删除后创建
validate: 核对实体类配置
update: 如果表不存在就创建,存在的话核对表结构,若增加属性会自动增加字段
------解决方案--------------------
在oracle建了数据库吗?