java - Table generated by hibernate but not showing in mysql database -
hi working on code of book called master spring mvc
, using mysql database
instead of embeded database
. in book author have used xml
based configuration using java based. till here working fine.
the problem facing when running code in tomcat
server , logs (hibernate logs table generation particular table) fine table getting generated in database not table called historic
. have attached code along log shows table generated:
please not multi module project , therefore webapp, database configured separately. 1) hibernate log genrerate particular table
hibernate log class:
create table historic ( historic_type varchar(31) not null, id integer not null auto_increment, adj_close double precision, change_percent double precision, close double precision not null, from_date datetime, high double precision not null, interval varchar(255), low double precision not null, open double precision not null, to_date datetime, volume double precision not null, ask double precision, bid double precision, index_code varchar(255), stock_code varchar(255), primary key (id) ) engine=myisam
2)database configuraton file
@configuration @componentscan("edu.zipcloud.cloudstreetmarket.core.entities") @enabletransactionmanagement public class jpahibernatespringconfig { private logger logger = loggerfactory.getlogger(this.getclass()); public datasource datasource() { logger.info("============================[data source configuration: began]"); basicdatasource ds = new basicdatasource(); ds.setdriverclassname("com.mysql.jdbc.driver"); ds.seturl("jdbc:mysql://localhost/cloudstreet"); ds.setusername("root"); ds.setpassword("root"); logger.info("============================[data source configuration: ends]"); return ds; } @bean public localcontainerentitymanagerfactorybean localcontainerentitymanagerfactorybean() { logger.info("============================[localcontainerentitymanagerfactorybean: began]"); localcontainerentitymanagerfactorybean bean = new localcontainerentitymanagerfactorybean(); bean.setdatasource(datasource()); bean.setpersistenceunitname("jpadata"); bean.setpackagestoscan("edu.zipcloud.cloudstreetmarket.core"); bean.setpersistenceproviderclass(hibernatepersistenceprovider.class); bean.setjpaproperties(hibernatejpaproperties()); logger.info("===========================[localcontainerentitymanagerfactorybean: ends]"); return bean; } public properties hibernatejpaproperties() { logger.info("============================[hibernatejpaproperties: began]"); properties properties = new properties(); properties.put("hibernate.dialect", "org.hibernate.dialect.mysql5dialect"); properties.put("hibernate.show_sql", "true"); properties.put("hibernate.format_sql", "true"); properties.put("hibernate.hbm2ddl.auto", "create"); properties.put("hibernate.naming-strategy", "org.hibernate.cfg.improvednamingstrategy"); properties.put("hibernate.default_schema", "public"); logger.info("============================[hibernatejpaproperties: ends]"); return properties; } @bean public jpatransactionmanager jpatransactionmanager() { logger.info("============================[jpatransactionmanager: began]"); jpatransactionmanager manager = new jpatransactionmanager(); manager.setentitymanagerfactory(localcontainerentitymanagerfactorybean().getobject()); logger.info("============================[jpatransactionmanager: ends]"); return manager; } }
2) dispatcherservlet:
public class dispatcherservletconifg extends abstractannotationconfigdispatcherservletinitializer { @override protected class<?>[] getrootconfigclasses() { return new class[] { jpahibernatespringconfig.class }; } @override protected class<?>[] getservletconfigclasses() { return new class[] { webservletinit.class }; } @override protected string[] getservletmappings() { return new string[] { "/" }; }
3) historic entity
@entity @inheritance(strategy = inheritancetype.single_table) @discriminatorcolumn(name = "historic_type") @table(name = "historic") public abstract class historic implements serializable { private static final long serialversionuid = -802306391915956578l; @id @generatedvalue(strategy=generationtype.identity) private int id; private double open; private double high; private double low; private double close; private double volume; @column(name = "adj_close") private double adjclose; @column(name = "change_percent") private double changepercent; @temporal(temporaltype.timestamp) @column(name = "from_date") private date fromdate; @temporal(temporaltype.timestamp) @column(name = "to_date") private date todate; @enumerated(enumtype.string) @column(name = "interval") private quotesinterval interval;
please take @ logs , if need other information let me know.
thanks.
i think problem mysql keyword being used column name "interval" try other name
we can rename interval field below
@enumerated(enumtype.string) @column(name = "quotesinterval") private quotesinterval interval;
or
any name matches need.
bottom line should not use mysql keywords
Comments
Post a Comment