I have always used hibernate.cfg.xml to configure Hibernate. For various reasons I need to move all the configuration to Java and I have problem with mapping entities.
Previously in XML my mappings looked like this:
<mapping class="com.mycompany.enitites.Test" />
Everything is annotation driven, so I did not need to specify anything else.
Now that I configure everything using Hibernate's Configuration.class
, how to add the mappings? I tried configuration.addClass(Test.class)
but this throws an error that file test.hbm.xml
does not exist. And I don't want to use it, I want Hibernate to read the mappings from annotations.
EDIT: I tried configuration.addAnnotatedClass(Test.class)
but this throws relation "test" does not exist
on the first encountered query that involved Test.class
entity.
I made grammar mistake in the following line:
configuration.setProperty("hibernate.hbm2ddl.auto", "update");
Which preventing Hibernate from creating tables in startup and thus not finding them...
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.