简体   繁体   English

如何让 hibernate 为我制作数据库? (行家和Java)

[英]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.我有大学作业,要求我用 hibernate 创建一个简单的数据库,但我遇到了很多麻烦......我希望有人能给我一个解决方案。

I set the pom.xml with MySQL and hibernate dependencies;我设置了 pom.xml 与 MySQL 和 hibernate 依赖项; after that I made the hibernate.cfg.xml file in which I give it the connection URL.之后我制作了 hibernate.cfg.xml 文件,在其中我给它连接 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我正在尝试做带注释的东西,所以我不必做其他 xml 文件......但它说一旦我运行程序它就找不到数据库,即使我在我的 cfg 文件中指定必须创建数据库

<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. Hibernate 不会通过此属性为您创建数据库,只会创建表。如果它不存在,您可以通过向 URL 添加参数来创建它。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Java ME中向用户询问一些数字? - How can I ask the user for some numbers in Java ME? 在Java中,我可以要求系统告诉我文件的字符集吗? - In Java can I ask the system to tell me the charset of a file? 如何使用 Hibernate、Java 和 Gradle 连接到数据库? - How do I make a connection to a database with Hibernate, Java, and Gradle? 如何让 Hibernate 在外键(JoinColumn)上创建索引? - How can I ask Hibernate to create an index on a foreign key (JoinColumn)? 我如何向Maven索取默认存储库列表? - How can I ask Maven for a list of the default repositories? 在Java中,如果前一个查询的值为true,如何使我的程序仅询问下一个查询? - In Java, how can I make my program only ask the next inquiry if the previous inquiry's value is true? 如何让计算器询问用户是否想在 Java 中执行另一个计算? - How can I make a calculator ask the user if they want to perform another calculation in Java? 如何用java创建一个“不要再问我”对话框弹出框? - How to make a “do not ask me again” dialog pop-up box with java? 你能告诉我如何正确编辑这个 java 注释 mongodb @Query(&quot;{ &#39;ask&#39;: ?0}&quot;) 吗? - Can you tell me how to edit this java annotation mongodb correctly @Query("{ 'ask': ?0}")? 如何在Java中使数据库具有可变列的表? - How I can make a table in database having variable columns in Java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM