2011-12-23 105 views
6

我使用hibernate与嵌入式德比,我想休眠创建数据库和表,所以我尝试了以下配置,但我得到的错误:java.sql.SQLException:架构'ROOT'不存在

java.sql.SQLException: Schema 'ROOT' does not exist 

这里/我的配置:

<bean id="sessionFactory" 
    class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> 

    <property name="dataSource" ref="dataSource" /> 
    <property name="packagesToScan" value="com.myapp.domain" /> 


    <property name="hibernateProperties"> 
     <value> 
      hibernate.dialect=org.hibernate.dialect.DerbyDialect 
      hibernate.hbm2ddl.auto=create 
      hibernate.show_sql=false 
      hibernate.format_sql=false 
     </value> 
    </property> 

</bean> 

<bean id="dataSource" 
    class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 

    <property name="driverClassName" value="org.apache.derby.jdbc.EmbeddedDriver" /> 

    <property name="url" value="jdbc:derby:test;create=true" /> 

    <property name="username" value="root" /> 

    <property name="password" value="root" /> 

</bean> 

<bean id="transactionManager" 
    class="org.springframework.orm.hibernate3.HibernateTransactionManager"> 
    <property name="sessionFactory" ref="sessionFactory" /> 
</bean> 


<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" /> 

UPDATE:这是我第一次使用的德比战,所以我也许有一些缺失的信息,所以我有一个问题:

我一定要配置嵌入式Derby在这里:

http://db.apache.org/derby/papers/DerbyTut/install_software.html

更新2:我删除类路径负责在数据库中插入演示数据的import.sql脚本文件,我发现了这有创建数据库表的错误:

1202 [main] INFO org.hibernate.tool.hbm2ddl.SchemaExport - Running hbm2ddl schema export 
1202 [main] INFO org.hibernate.tool.hbm2ddl.SchemaExport - exporting generated schema to database 
1359 [main] ERROR org.hibernate.tool.hbm2ddl.SchemaExport - Unsuccessful: create table users (user_id bigint generated by default as identity unique, address varchar(255), email varchar(155) not null, mobile varchar(25), name varchar(25) not null, password varchar(255) not null, primary key (user_id)) 
1359 [main] ERROR org.hibernate.tool.hbm2ddl.SchemaExport - Constraints 'SQL111223214919671' and 'SQL111223214919670' have the same set of columns, which is not allowed. 
1359 [main] INFO org.hibernate.tool.hbm2ddl.SchemaExport - schema export complete 
1360 [main] WARN org.hibernate.util.JDBCExceptionReporter - SQL Warning: 10000, SQLState: 01J01 
1360 [main] WARN org.hibernate.util.JDBCExceptionReporter - Database 'test' not created, connection made to existing database instead. 
+0

从未使用德比。但你有没有定义数据库的用户“根”(有权访问测试基) – Vinze 2011-12-23 11:21:54

+0

好吧,我只是想在这里配置,我认为它应该创建数据库与上面的用户/通http:// stackoverflow.com/questions/8459284/using-hibernate-with-embedded-derby/8463463#comment10693363_8463463 – 2011-12-23 11:28:30

+0

继承人嵌入式驱动程序tut:https://db.apache.org/derby/papers/DerbyTut/embedded_intro.html。但是你的代码看起来很好 – oers 2011-12-23 11:41:03

回答

0

对不起,从来没有使用过德比,不过我认为这个问题是,Hibernate无法创建任何数据库,数据库用户或数据库模式为您服务。这只是一个猜测,但对我来说,错误消息表明您还需要用户的数据库架构。尝试事先创建数据库,数据库用户根和模式根,然后使用Hibernate连接以创建表。

+0

; create = true应该注意 – oers 2011-12-23 13:11:59

+0

@oers:谢谢,没有看到。但我确信hibernate不能创建一个模式,并且它看起来像用户的模式缺失。所以,我会尝试使用create = false并事先创建数据库和模式。 – tscho 2011-12-23 13:21:36

+0

@ tscho,我更新了帖子,请指教。 – 2011-12-23 19:53:01

0

最简单的解决办法是配置你的数据库属性和进行模式相同的用户名,但在资本窝前:架构APP用户应用

希望我的回答可以帮助您。