java - Cannot create tables and load data in H2 using JPA -
java - Cannot create tables and load data in H2 using JPA -
i have jpa project uses hibernate , h2. next maven pom dependency list:
class="lang-xml prettyprint-override"> <dependency> <groupid>com.h2database</groupid> <artifactid>h2</artifactid> <version>1.4.181</version> </dependency> <dependency> <groupid>org.hibernate</groupid> <artifactid>hibernate-core</artifactid> <version>4.3.6.final</version> </dependency> <dependency> <groupid>org.hibernate</groupid> <artifactid>hibernate-entitymanager</artifactid> <version>4.3.6.final</version> </dependency>
the next project structure:
the next content of blood_donor_create.sql
:
create table if not exists `blood_type` ( `id` integer not null, `blood_type` char(3) not null, primary key (`id`) ) create table if not exists `donation` ( `id` bigint not null auto_increment, `date` date not null, `location` varchar(150) not null, `donor_id` bigint not null, primary key (`id`), key `donation_donor` (`donor_id`), constraint `donation_donor` foreign key (`donor_id`) references `donor` (`id`) ) create table if not exists `donor` ( `id` bigint not null auto_increment, `name` varchar(50) not null, `myanmar_name` varchar(100) not null, `email` varchar(50) not null, `facebook` varchar(50) not null, `phone` integer not null, `blood_type_id` integer not null, primary key (`id`), key `donor_blood_type` (`blood_type_id`), constraint `donor_blood_type` foreign key (`blood_type_id`) references `blood_type` (`id`) )
and next content of blood_donor_load.sql
:
insert `blood_type` (`id`, `blood_type`) values (1, 'a+'), (2, 'a-'), (3, 'b+'), (4, 'b-'), (5, 'o+'), (6, 'o-'), (7, 'ab+'), (8, 'ab-');
the next content of persistence.xml
:
<persistence-unit name="blooddonorpu" transaction-type="resource_local"> <provider>org.hibernate.jpa.hibernatepersistenceprovider</provider> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.h2dialect"/> <property name="javax.persistence.jdbc.driver" value="org.h2.driver"/> <property name="javax.persistence.jdbc.url" value="jdbc:h2:file:~/blooddonor"/> <property name="javax.persistence.schema-generation.database.action" value="create"/> <property name="javax.persistence.schema-generation.create-source" value="script"/> <property name="javax.persistence.schema-generation.create-script-source" value="sql/blood_donor_load.sql"/> <property name="javax.persistence.sql-load-script-source" value="sql/blood_donor_load.sql"/> </properties> </persistence-unit>
running programme causes next exceptions:
class="lang-none prettyprint-override">exception in thread "main" javax.persistence.persistenceexception: unable execute jpa schema generation create command [insert `blood_type` (`id`, `blood_type`) values] @ org.hibernate.jpa.internal.schemagen.generationtargettodatabase.acceptcreatecommands(generationtargettodatabase.java:64) @ org.hibernate.jpa.internal.schemagen.jpaschemagenerator.dogeneration(jpaschemagenerator.java:507) @ org.hibernate.jpa.internal.schemagen.jpaschemagenerator.access$300(jpaschemagenerator.java:69) @ org.hibernate.jpa.internal.schemagen.jpaschemagenerator$generation.execute(jpaschemagenerator.java:184) @ org.hibernate.jpa.internal.schemagen.jpaschemagenerator.performgeneration(jpaschemagenerator.java:76) @ org.hibernate.jpa.boot.internal.entitymanagerfactorybuilderimpl$4.perform(entitymanagerfactorybuilderimpl.java:857) @ org.hibernate.jpa.boot.internal.entitymanagerfactorybuilderimpl$4.perform(entitymanagerfactorybuilderimpl.java:843) @ org.hibernate.boot.registry.classloading.internal.classloaderserviceimpl.withtccl(classloaderserviceimpl.java:398) @ org.hibernate.jpa.boot.internal.entitymanagerfactorybuilderimpl.build(entitymanagerfactorybuilderimpl.java:842) @ org.hibernate.jpa.hibernatepersistenceprovider.createentitymanagerfactory(hibernatepersistenceprovider.java:75) @ org.hibernate.ejb.hibernatepersistence.createentitymanagerfactory(hibernatepersistence.java:54) @ javax.persistence.persistence.createentitymanagerfactory(persistence.java:55) @ javax.persistence.persistence.createentitymanagerfactory(persistence.java:39) @ org.bitbucket.infovillavendor.blooddonor.launcher.main(launcher.java:10) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:483) @ com.intellij.rt.execution.application.appmain.main(appmain.java:134) caused by: org.h2.jdbc.jdbcsqlexception: table "blood_type" not found; sql statement: insert `blood_type` (`id`, `blood_type`) values [42102-181] @ org.h2.message.dbexception.getjdbcsqlexception(dbexception.java:345) @ org.h2.message.dbexception.get(dbexception.java:179) @ org.h2.message.dbexception.get(dbexception.java:155) @ org.h2.command.parser.readtableorview(parser.java:5227) @ org.h2.command.parser.readtableorview(parser.java:5204) @ org.h2.command.parser.parseinsert(parser.java:1025) @ org.h2.command.parser.parseprepared(parser.java:401) @ org.h2.command.parser.parse(parser.java:305) @ org.h2.command.parser.parse(parser.java:277) @ org.h2.command.parser.preparecommand(parser.java:242) @ org.h2.engine.session.preparelocal(session.java:446) @ org.h2.engine.session.preparecommand(session.java:388) @ org.h2.jdbc.jdbcconnection.preparecommand(jdbcconnection.java:1189) @ org.h2.jdbc.jdbcstatement.executeinternal(jdbcstatement.java:171) @ org.h2.jdbc.jdbcstatement.execute(jdbcstatement.java:159) @ org.hibernate.jpa.internal.schemagen.generationtargettodatabase.acceptcreatecommands(generationtargettodatabase.java:61) ... 18 more
what might wrong here?
i don't think need quotes in table name in creation or insertion.
java jpa h2
Comments
Post a Comment