简体   繁体   中英

How can I ask hibernate to make a Database for me? (maven & java)

I have University homework that asks me to create a simple database with hibernate, but I'm having a lot of troubles... I would like if someone would show me a solution.

I set the pom.xml with MySQL and hibernate dependencies; after that I made the hibernate.cfg.xml file in which I give it the connection URL. I am trying to do the annotated stuff so I don't have to do the other xml file... but it says that it can't find the database once I run the program, even if I specified in the cfg file that I have to create the database

<property name = "hibernate.hbm2ddl.auto">create</property>

Hibernate won't create the database for you by this property, only the tables.you can create it if it is not present already by adding a parameter to the URL.

jdbc:mysql://db:3306/mydb?createDatabaseIfNotExist=true

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM