java - com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database 'xyz' . hbm2ddl.auto=update not working -
i creating 1 application using spring, hibernate , mysql. setting hibernate.hbm2ddl.auto=update, suppose force mysql create database/tables if not exist. still reasons hibernate not creating database , throwing exception. please have used sorts of dialect please see below in vain.
hibernate.properties file
#jdbc properties jdbc.driverclassname=com.mysql.jdbc.driver jdbc.url=jdbc:mysql://localhost:3306/emusicstoredb jdbc.username=root jdbc.password=mysql@123 #hibernate properties hibernate.dialect=org.hibernate.dialect.mysql5dialect hibernate.show_sql=true hibernate.hbm2ddl.auto=update hibernate.format_sql=true
applicationcontext.xml file
<context:property-placeholder location="/web-inf/hibernate.properties" /> <bean id="datasource" class="org.springframework.jdbc.datasource.drivermanagerdatasource"> <property name="driverclassname" value="${jdbc.driverclassname}" /> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> </bean> <bean id="sessionfactory" class="org.springframework.orm.hibernate4.localsessionfactorybean"> <property name="datasource" ref="datasource" /> <property name="hibernateproperties"> <props> <prop key="hibernate.dialect">${hibernate.dialect}</prop> <prop key="hibernate.show_sql">${hibernate.show_sql}</prop> <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop> <prop key="hibernate.format_sql">${hibernate.format_sql}</prop> </props> </property> <property name="packagestoscan"> <list> <value>com.emusicstore</value> </list> </property> </bean> <bean id="transactionmanager" class="org.springframework.orm.hibernate4.hibernatetransactionmanager"> <property name="sessionfactory" ref="sessionfactory" /> </bean> <bean id="multipartresolver" class="org.springframework.web.multipart.commons.commonsmultipartresolver"> <property name="maxuploadsize" value="1024000" /> </bean> </beans>
console
info: hcann000001: hibernate commons annotations {4.0.4.final} apr 14, 2017 4:42:25 pm org.hibernate.version logversion info: hhh000412: hibernate core {4.3.1.final} apr 14, 2017 4:42:25 pm org.hibernate.cfg.environment <clinit> info: hhh000206: hibernate.properties not found apr 14, 2017 4:42:25 pm org.hibernate.cfg.environment buildbytecodeprovider info: hhh000021: bytecode provider name : javassist apr 14, 2017 4:42:26 pm org.hibernate.engine.jdbc.internal.jdbcservicesimpl configure warn: hhh000342: not obtain connection query metadata : unknown database 'emusicstoredb' apr 14, 2017 4:42:26 pm org.hibernate.dialect.dialect <init> info: hhh000400: using dialect: org.hibernate.dialect.mysql5dialect apr 14, 2017 4:42:26 pm org.hibernate.engine.jdbc.internal.lobcreatorbuilder usecontextuallobcreation info: hhh000422: disabling contextual lob creation connection null apr 14, 2017 4:42:27 pm org.hibernate.engine.transaction.internal.transactionfactoryinitiator initiateservice info: hhh000399: using default transaction strategy (direct jdbc transactions) apr 14, 2017 4:42:27 pm org.hibernate.hql.internal.ast.astquerytranslatorfactory <init> info: hhh000397: using astquerytranslatorfactory apr 14, 2017 4:42:28 pm org.hibernate.tool.hbm2ddl.schemaupdate execute info: hhh000228: running hbm2ddl schema update apr 14, 2017 4:42:28 pm org.hibernate.tool.hbm2ddl.schemaupdate execute info: hhh000102: fetching database metadata apr 14, 2017 4:42:28 pm org.hibernate.tool.hbm2ddl.schemaupdate execute error: hhh000319: not database metadata com.mysql.jdbc.exceptions.jdbc4.mysqlsyntaxerrorexception: unknown database 'emusicstoredb' @ sun.reflect.nativeconstructoraccessorimpl.newinstance0(native method) @ sun.reflect.nativeconstructoraccessorimpl.newinstance(unknown source) @ sun.reflect.delegatingconstructoraccessorimpl.newinstance(unknown source) @ java.lang.reflect.constructor.newinstance(unknown source) @ com.mysql.jdbc.util.handlenewinstance(util.java:406) @ com.mysql.jdbc.util.getinstance(util.java:381) @ com.mysql.jdbc.sqlerror.createsqlexception(sqlerror.java:1030) @ com.mysql.jdbc.sqlerror.createsqlexception(sqlerror.java:956) @ com.mysql.jdbc.mysqlio.checkerrorpacket(mysqlio.java:3491) @ com.mysql.jdbc.mysqlio.checkerrorpacket(mysqlio.java:3423) @ com.mysql.jdbc.mysqlio.checkerrorpacket(mysqlio.java:910) @ com.mysql.jdbc.mysqlio.secureauth411(mysqlio.java:3923) @ com.mysql.jdbc.mysqlio.dohandshake(mysqlio.java:1273) @ com.mysql.jdbc.connectionimpl.createnewio(connectionimpl.java:2031) @ com.mysql.jdbc.connectionimpl.<init>(connectionimpl.java:718) @ com.mysql.jdbc.jdbc4connection.<init>(jdbc4connection.java:46) @ sun.reflect.nativeconstructoraccessorimpl.newinstance0(native method) @ sun.reflect.nativeconstructoraccessorimpl.newinstance(unknown source) @ sun.reflect.delegatingconstructoraccessorimpl.newinstance(unknown source) @ java.lang.reflect.constructor.newinstance(unknown source) @ com.mysql.jdbc.util.handlenewinstance(util.java:406) @ com.mysql.jdbc.connectionimpl.getinstance(connectionimpl.java:302) @ com.mysql.jdbc.nonregisteringdriver.connect(nonregisteringdriver.java:282) @ java.sql.drivermanager.getconnection(unknown source) @ java.sql.drivermanager.getconnection(unknown source) @ org.springframework.jdbc.datasource.drivermanagerdatasource.getconnectionfromdrivermanager(drivermanagerdatasource.java:153) @ org.springframework.jdbc.datasource.drivermanagerdatasource.getconnectionfromdriver(drivermanagerdatasource.java:144) @ org.springframework.jdbc.datasource.abstractdriverbaseddatasource.getconnectionfromdriver(abstractdriverbaseddatasource.java:155) @ org.springframework.jdbc.datasource.abstractdriverbaseddatasource.getconnection(abstractdriverbaseddatasource.java:120) @ org.hibernate.engine.jdbc.connections.internal.datasourceconnectionproviderimpl.getconnection(datasourceconnectionproviderimpl.java:139) @ org.hibernate.tool.hbm2ddl.suppliedconnectionproviderconnectionhelper.prepare(suppliedconnectionproviderconnectionhelper.java:51) @ org.hibernate.tool.hbm2ddl.schemaupdate.execute(schemaupdate.java:194) @ org.hibernate.tool.hbm2ddl.schemaupdate.execute(schemaupdate.java:178) @ org.hibernate.internal.sessionfactoryimpl.<init>(sessionfactoryimpl.java:521) @ org.hibernate.cfg.configuration.buildsessionfactory(configuration.java:1857) @ org.hibernate.cfg.configuration.buildsessionfactory(configuration.java:1928) @ org.springframework.orm.hibernate4.localsessionfactorybuilder.buildsessionfactory(localsessionfactorybuilder.java:372) @ org.springframework.orm.hibernate4.localsessionfactorybean.buildsessionfactory(localsessionfactorybean.java:454) @ org.springframework.orm.hibernate4.localsessionfactorybean.afterpropertiesset(localsessionfactorybean.java:439) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.invokeinitmethods(abstractautowirecapablebeanfactory.java:1625) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.initializebean(abstractautowirecapablebeanfactory.java:1562) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:539) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:476) @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:303) @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:230) @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:299) @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:194) @ org.springframework.beans.factory.support.defaultlistablebeanfactory.preinstantiatesingletons(defaultlistablebeanfactory.java:743) @ org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:757) @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:480) @ org.springframework.web.context.contextloader.configureandrefreshwebapplicationcontext(contextloader.java:403) @ org.springframework.web.context.contextloader.initwebapplicationcontext(contextloader.java:306) @ org.springframework.web.context.contextloaderlistener.contextinitialized(contextloaderlistener.java:106) @ org.apache.catalina.core.standardcontext.listenerstart(standardcontext.java:4812) @ org.apache.catalina.core.standardcontext.startinternal(standardcontext.java:5255) @ org.apache.catalina.util.lifecyclebase.start(lifecyclebase.java:150) @ org.apache.catalina.core.containerbase$startchild.call(containerbase.java:1408) @ org.apache.catalina.core.containerbase$startchild.call(containerbase.java:1398) @ java.util.concurrent.futuretask.run(unknown source) @ java.util.concurrent.threadpoolexecutor.runworker(unknown source) @ java.util.concurrent.threadpoolexecutor$worker.run(unknown source) @ java.lang.thread.run(unknown source)
pom.xml
<project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelversion>4.0.0</modelversion> <groupid>mywebsite</groupid> <artifactid>emusicstore</artifactid> <packaging>war</packaging> <version>0.0.1-snapshot</version> <name>emusicstore maven webapp</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupid>junit</groupid> <artifactid>junit</artifactid> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-webmvc</artifactid> <version>4.1.4.release</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-core</artifactid> <version>4.1.4.release</version> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework/spring-context --> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-context</artifactid> <version>4.1.4.release</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-orm</artifactid> <version>4.1.4.release</version> </dependency> <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core --> <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java --> <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java --> <!-- https://mvnrepository.com/artifact/jstl/jstl --> <dependency> <groupid>jstl</groupid> <artifactid>jstl</artifactid> <version>1.2</version> </dependency> <!-- https://mvnrepository.com/artifact/jstl/jstl --> <dependency> <groupid>taglibs</groupid> <artifactid>standard</artifactid> <version>1.1.2</version> </dependency> <dependency> <groupid>commons-fileupload</groupid> <artifactid>commons-fileupload</artifactid> <version>1.2.2</version> </dependency> <dependency> <groupid>commons-io</groupid> <artifactid>commons-io</artifactid> <version>2.4</version> </dependency> <dependency> <groupid>mysql</groupid> <artifactid>mysql-connector-java</artifactid> <version>5.1.6</version> </dependency> <dependency> <groupid>org.hibernate</groupid> <artifactid>hibernate-core</artifactid> <version>4.3.1.final</version> </dependency> <dependency> <groupid>org.hibernate.javax.persistence</groupid> <artifactid>hibernate-jpa-2.0-api</artifactid> <version>1.0.0.final</version> </dependency> <dependency> <groupid>javax.servlet</groupid> <artifactid>servlet-api</artifactid> <version>2.5</version> <scope>provided</scope> </dependency> </dependencies> <build> <finalname>emusicstore</finalname> </build> </project>
please note: have used following dialects:
org.hibernate.dialect.mysql5dialect
org.hibernate.dialect.mysqlinnodbdialect
org.hibernate.dialect.mysqldialect
i created database , threw exception table instead of database.
and did maven update, clean project, delete .m2 folder , wasted 4 hours in vain. please help.
com.mysql.jdbc.exceptions.jdbc4.mysqlsyntaxerrorexception: unknown database 'emusicstoredb'
this exception because of application not found database name -> emusicstoredb
hbm2ddl.auto
property of hibernate either creates, update or validates database table. not responsible create database, should create database name emusicstoredb
first run app.
Comments
Post a Comment