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

Time:11-21

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>

CodePudding user response:

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
  • Related