I want my Spring application to automatically generate schema and DB tables ... I read some Q and am questions in this section and I set my DB address:
H2DataSource.setUrl ("jdbc: h2: mem: tmp.db; INIT = CREATE DIAGRAM IF NOT EXISTS GPSTRACKER");
and I annotated my objects as:
@Entity
@Table (name = "tblGps", schema = "GPSTRACKER")
but the db schema is still not created.
Here is my conclusion to the magazine. Hibernate is trying to create tables, but cannot find a schema!
What am I doing wrong? Any suggestions?
Log output
2015-04-20 22:29:38.211 INFO 7056 --- [ost-startStop-1] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [ name: default ...] 2015-04-20 22:29:38.356 INFO 7056 --- [ost-startStop-1] org.hibernate.Version : HHH000412: Hibernate Core {4.3.8.Final} 2015-04-20 22:29:38.360 INFO 7056 --- [ost-startStop-1] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found 2015-04-20 22:29:38.362 INFO 7056 --- [ost-startStop-1] org.hibernate.cfg.Environment : HHH000021: Bytecode provider name : javassist 2015-04-20 22:29:38.745 INFO 7056 --- [ost-startStop-1] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {4.0.5.Final} 2015-04-20 22:29:38.899 INFO 7056 --- [ost-startStop-1] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect 2015-04-20 22:29:39.202 INFO 7056 --- [ost-startStop-1] ohhiast.ASTQueryTranslatorFactory : HHH000397: Using ASTQueryTranslatorFactory 2015-04-20 22:29:39.795 INFO 7056 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaExport : HHH000227: Running hbm2ddl schema export 2015-04-20 22:29:39.801 ERROR 7056 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaExport : HHH000389: Unsuccessful: drop table GPSTRACKER.tbl_gps if exists 2015-04-20 22:29:39.801 ERROR 7056 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaExport : Schema "GPSTRACKER" nicht gefunden Schema "GPSTRACKER" not found; SQL statement: drop table GPSTRACKER.tbl_gps if exists [90079-185]
EntityManagerFactory
@Bean public EntityManagerFactory entityManagerFactory() { HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); vendorAdapter.setGenerateDdl(true); vendorAdapter.setShowSql(true); vendorAdapter.setDatabasePlatform(MyAppSettings.getDbPlattform()); HibernateJpaDialect jpd = new HibernateJpaDialect(); LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean(); factory.setJpaDialect(jpd); factory.setJpaVendorAdapter(vendorAdapter); factory.setPackagesToScan(MyAppSettings.packagesToScan); factory.setDataSource(MyDataSource()); return factory.getObject(); }
Data source
DriverManagerDataSource H2DataSource = new DriverManagerDataSource(); H2DataSource.setDriverClassName("org.h2.Driver"); H2DataSource.setUrl("jdbc:h2:mem:tmp.db;INIT=CREATE SCHEMA IF NOT EXISTS GPSTRACKER"); H2DataSource.setUsername("sa"); H2DataSource.setPassword("");
@pvgoddijn I donβt remember exactly, and I canβt find the code right now. But I guess I needed to return LocalEntityManagerFactory instead of EntityManagerFactory ... or sth. good luck! maybe I can find the code in the following days ...
source share