我正在开发一个angularjs spring mvc项目,并面临使用hibernate创建表的问题。
INFO: HV000001: Hibernate Validator 5.2.2.Final
Jun 18, 2016 4:54:49 AM org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: HHH000227: Running hbm2ddl schema export
Hibernate: drop table if exists AppUser
Jun 18, 2016 4:54:49 AM org.hibernate.tool.hbm2ddl.SchemaExport perform
ERROR: HHH000389: Unsuccessful: drop table if exists AppUser
Jun 18, 2016 4:54:49 AM org.hibernate.tool.hbm2ddl.SchemaExport perform
ERROR: ORA-00933: SQL command not properly ended
Hibernate: create table AppUser (id integer not null auto_increment, dob varchar(255), email varchar(50), firstName varchar(255), lastName varchar(255), password varchar(255) not null, primary key (id))
Jun 18, 2016 4:54:49 AM org.hibernate.tool.hbm2ddl.SchemaExport perform
ERROR: HHH000389: Unsuccessful: create table AppUser (id integer not null auto_increment, dob varchar(255), email varchar(50), firstName varchar(255), lastName varchar(255), password varchar(255) not null, primary key (id))
Jun 18, 2016 4:54:49 AM org.hibernate.tool.hbm2ddl.SchemaExport perform
ERROR: ORA-00907: missing right parenthesis
模型类是一个看起来像
的简单类@Entity
public class AppUser {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@Email
@Size(max = 50)
private String email;
@Column
private String dob;
@Column
private String firstName;
@Column
private String lastName;
@Column(name = "password", nullable = false)
private String password;
//getter setter
}
数据配置文件看起来像
@Configuration
@EnableTransactionManagement
public class AppDatabaseConfig {
@Bean
public HikariDataSource dataSource() {
final HikariDataSource ds = new HikariDataSource();
ds.setMaximumPoolSize(100);
ds.setDriverClassName("oracle.jdbc.driver.OracleDriver");
ds.setJdbcUrl("jdbc:oracle:thin:@localhost:1521:XE"); ;
ds.setUsername("");
ds.setPassword("");
return ds;
}
@Bean
public HibernateTransactionManager transactionManager() {
HibernateTransactionManager manager = new HibernateTransactionManager();
manager.setSessionFactory(hibernate5SessionFactoryBean().getObject());
return manager;
}
@Bean
public LocalSessionFactoryBean hibernate5SessionFactoryBean(){
LocalSessionFactoryBean localSessionFactoryBean = new LocalSessionFactoryBean();
localSessionFactoryBean.setDataSource(dataSource());
localSessionFactoryBean.setAnnotatedClasses(AppUser.class);
Properties properties = new Properties();
properties.put("hibernate.dialect","org.hibernate.dialect.MySQLDialect");
//properties.put("hibernate.current_session_context_class","thread");
properties.put("hibernate.hbm2ddl.auto","create");
properties.put("hibernate.show_sql","true");
localSessionFactoryBean.setHibernateProperties(properties);
return localSessionFactoryBean;
}
}
我尝试过chaning update / createdrop / create但每次都会出错。数据库不包含该表。不知道怎么解决这个问题?
答案 0 :(得分:0)
你使用的是错误的方言。
properties.put("hibernate.dialect","org.hibernate.dialect.MySQLDialect")
对于Oracle 11G,您必须使用
org.hibernate.dialect.Oracle10gDialect
请参阅官方链接以选择合适的方言
https://docs.jboss.org/hibernate/orm/3.6/reference/en-US/html/session-configuration.html