Hibernate java.sql.SQLException:Schema';根';不存在

Hibernate java.sql.SQLException:Schema';根';不存在,hibernate,jakarta-ee,derby,javadb,hbm2ddl,Hibernate,Jakarta Ee,Derby,Javadb,Hbm2ddl,我正在将hibernate与嵌入式derby一起使用,我希望hibernate创建数据库和表,因此我尝试了以下配置,但出现了错误: java.sql.SQLException: Schema 'ROOT' does not exist 以下是我的配置: <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">

我正在将hibernate与嵌入式derby一起使用,我希望hibernate创建数据库和表,因此我尝试了以下配置,但出现了错误:

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" />

很抱歉,我本人从未使用过Derby,但我认为问题在于Hibernate无法为您创建任何数据库、数据库用户或数据库模式。这只是一个猜测,但对我来说,错误消息表明您还需要用户的数据库模式。尝试预先创建数据库、数据库用户根和模式根,然后连接Hibernate来创建表

从类路径中删除import.sql文件并运行应用程序后,我发现错误是创建了数据库,但由于这个问题,hbm2ddl没有创建表 在此声明:

主键不能定义为唯一的,因为它是由数据库本身处理的


因此,当我从主键中删除unique属性时,错误就消失了。

最简单的解决方案是配置数据库属性,并使schema与用户名相同,但使用大写字母,例如:schema APP user APP


希望我的回答能有所帮助。

从未使用过德比。但是您是否为数据库定义了用户“root”(可以访问测试库)嗯,我只是尝试了这里的配置,我认为它应该使用上面的user/pass创建数据库这里有一个嵌入式驱动程序tut:。但是您的代码看起来很好,它说模式是在该模式中的某些内容被创建时创建的。您能看到执行了哪些sql语句吗?也许冬眠(或春天)从这里开始。@Vinze,@oers我更新了帖子,请告知。;create=true应该注意that@oers:谢谢,我没看到。但是我很确定hibernate无法创建模式,而且看起来用户的模式丢失了。因此,我将尝试使用create=false并预先创建数据库和模式。
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.