H2嵌入式数据库的模式相关问题

时间:2014-08-18 17:46:09

标签: java mysql sql hibernate

我正在构建一个Java Swing Desktop应用程序,我遇到了数据库问题。在我制作了架构" studenti"和表" studenti.ocjene_studenata"在sql文件中,当我启动程序时,我收到以下消息。究竟是什么问题?我认为我都配置正确。我将显示消息f错误,xml配置应用程序,sql文件和注释变量。非常感谢!

ERROR: HHH000388: Unsuccessful: create table studenti.ocjene_studenata (ID integer generated by default as identity, godina_studiranja integer, ime_studenta varchar(255), baze_podataka integer, matematika integer, napredne_baze_podataka integer, objektno_orijentirano_programiranje_2 integer, objektno_orijentirano_programiranje_1 integer, osnove_programiranja integer, programiranje integer, ocjena_mature integer, prezime_studenta varchar(255), prosjek double, primary key (ID))
kol 18, 2014 7:05:47 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
ERROR: Schema "STUDENTI" not found; SQL statement:

    create table studenti.ocjene_studenata (
        ID integer generated by default as identity,
        godina_studiranja integer,
        ime_studenta varchar(255),
        baze_podataka integer,
        matematika integer,
        napredne_baze_podataka integer,
        objektno_orijentirano_programiranje_2 integer,
        objektno_orijentirano_programiranje_1 integer,
        osnove_programiranja integer,
        programiranje integer,
        ocjena_mature integer,
        prezime_studenta varchar(255),
        prosjek double,
        primary key (ID)
    ) [90079-171]
kol 18, 2014 7:05:47 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000232: Schema update complete
kol 18, 2014 7:05:47 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 90079, SQLState: 90079
kol 18, 2014 7:05:47 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: Schema "STUDENTI" not found; SQL statement:
insert into studenti.ocjene_studenata (ID, godina_studiranja, ime_studenta, baze_podataka, matematika, napredne_baze_podataka, objektno_orijentirano_programiranje_2, objektno_orijentirano_programiranje_1, osnove_programiranja, programiranje, ocjena_mature, prezime_studenta, prosjek) values (null, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [90079-171]
Exception in thread "AWT-EventQueue-0" javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Schema "STUDENTI" not found; SQL statement:
insert into studenti.ocjene_studenata (ID, godina_studiranja, ime_studenta, baze_podataka, matematika, napredne_baze_podataka, objektno_orijentirano_programiranje_2, objektno_orijentirano_programiranje_1, osnove_programiranja, programiranje, ocjena_mature, prezime_studenta, prosjek) values (null, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [90079-171]
    at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1387)
    at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1310)
    at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1316)
    at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:881)
    at hr.tvz.programiranje.baza.DatabaseUtils.spremiRezultate(DatabaseUtils.java:18)
    at hr.tvz.programiranje.java.swing.glavni.GlavniOkvir$3.actionPerformed(GlavniOkvir.java:177)
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$200(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: org.hibernate.exception.GenericJDBCException: Schema "STUDENTI" not found; SQL statement:
insert into studenti.ocjene_studenata (ID, godina_studiranja, ime_studenta, baze_podataka, matematika, napredne_baze_podataka, objektno_orijentirano_programiranje_2, objektno_orijentirano_programiranje_1, osnove_programiranja, programiranje, ocjena_mature, prezime_studenta, prosjek) values (null, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [90079-171]
    at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54)
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
    at org.hibernate.engine.jdbc.internal.proxy.ConnectionProxyHandler.continueInvocation(ConnectionProxyHandler.java:146)
    at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
    at com.sun.proxy.$Proxy9.prepareStatement(Unknown Source)
    at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$2.doPrepare(StatementPreparerImpl.java:105)
    at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:166)
    at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareStatement(StatementPreparerImpl.java:103)
    at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.prepare(IdentityGenerator.java:89)
    at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:55)
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2936)
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3447)
    at org.hibernate.action.internal.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:81)
    at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:362)
    at org.hibernate.engine.spi.ActionQueue.addResolvedEntityInsertAction(ActionQueue.java:203)
    at org.hibernate.engine.spi.ActionQueue.addInsertAction(ActionQueue.java:183)
    at org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:167)
    at org.hibernate.event.internal.AbstractSaveEventListener.addInsertAction(AbstractSaveEventListener.java:321)
    at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:286)
    at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:192)
    at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:125)
    at org.hibernate.ejb.event.EJB3PersistEventListener.saveWithGeneratedId(EJB3PersistEventListener.java:78)
    at org.hibernate.event.internal.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:208)
    at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:151)
    at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:78)
    at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:843)
    at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:818)
    at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:822)
    at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:875)
    ... 38 more

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
<persistence-unit name="HibernatePersistenceUnit" transaction-type="RESOURCE_LOCAL">
<class>hr.tvz.programiranje.java.podaci.Podaci</class>
<properties>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
<property name="hibernate.connection.driver_class" value="org.h2.Driver"/>
<property name="hibernate.connection.url" value="jdbc:h2:~/uspjehStudenata"/>
<property name="hibernate.connection.username" value="sa"/>
<property name="hibernate.connection.password" value=""/>
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
</properties>
</persistence-unit>
</persistence>

create schema studenti;
create table studenti.ocjene_studenata(
ID INT generated always as identity,
ime_studenta varchar(300) not null,
prezime_studenta varchar (300) not null,
godina_studiranja int not null,
ocjena_mature int not null,
prosjek decimal(3,2) not null,
matematika int not null,
programiranje int not null,
objektno_orijentirano_programiranje_1 int not null,
objektno_orijentirano_programiranje_2 int not null,
osnove_programiranja int not null,
baze_podataka int not null,
napredne_baze_podataka int not null,
primary key(ID)
);

@Entity
@Table(name="studenti.ocjene_studenata")
public class Podaci {

    @Id
    @Column(name = "ID")
    @GeneratedValue
    private int ID;

    @Column(name = "ime_studenta")
    private String imeStudent;

    @Column(name = "prezime_studenta")
    private String prezimeStudent;

    @Column(name = "godina_studiranja")
    private int godinaStudiranjaInt;

    @Column(name = "ocjena_mature")
    private int ocjenaMatureInt;

    @Column(name = "prosjek")
    private double prosjekDbl;

    @Column(name = "matematika")
    private int ocjMatematika1Int;

    @Column(name = "programiranje")
    private int ocjProgramiranjeInt;

    @Column(name = "objektno_orijentirano_programiranje_1")
    private int ocjOOPIInt;

    @Column(name = "objektno_orijentirano_programiranje_2")
    private int ocjOOPIIInt;

    @Column(name = "osnove_programiranja")
    private int ocjOPInt;

    @Column(name = "baze_podataka")
    private int ocjBPInt;

    @Column(name = "napredne_baze_podataka")
    private int ocjNBPInt;

1 个答案:

答案 0 :(得分:1)

您可能需要查看此内容:

https://groups.google.com/forum/#!topic/h2-database/3ZL1GCcDv9M

这是一个很好的帐户,一个人创建一个新的架构,由于模式名称中的区分大小写而出错,并解决它们。他还提供了与不同场景的架构命名相关的各种错误。

他的最终解决方案实际上是在线程的底部,但我认为第一部分中的信息可能会更多地帮助您的特定情况。

线程的最终解决方案:

  

为了帮助别人陷入同样陷阱,我陷入了困境   (无论多么不可能)这里有一个小小的解释。   我用来连接数据库的库是发送剩余的   在连接信息映射中找到的值为JDBC getConnection as   属性。我保留了特定语句的模式名称   “架构”键仅供内部使用。在我测试的其他数据库上   我的项目,这不是问题,但H2偶然使用   来自连接属性的相同“schema”键以设置架构   与该连接一起使用。由于此值未正确引用,   它抛出了适当的错误。我假设我完全糊涂了   该错误来自我发送的create table语句。