I am experimenting with Hibernate for my Java web app. The following is part of my hibernate.cfg.xml, and I wondering how to map multiple database tables in the same configuration file. I use annotations to map my models to mysql database table, and I have multiple model classes (for example: models.Book), how to map the models in hibernate.cfg.xml?
com.mysql.jdbc.Driver
jdbc:mysql://localhost:3306/test_db
root
xxx
1
org.hibernate.dialect.MySQLDialect
thread
org.hibernate.cache.NoCacheProvider
true
validate
解决方案
We should not specify mappings in cfg.xml file. It has to be done by either annotations or XML.
For Annotations:
The cfg.xml file that is provided by you looks ok, if we are using the annotations to indicate database mappings with entity classes.
To use XML way of mapping between Entities and Tables, an hbm.xml file needs to be created and in that case, Replace
with something like
//all the database mappings
Sorry, if I understand your question wrongly.