hibernate.cfg.xml of Hibernate

前端 未结 2 442
旧巷少年郎
旧巷少年郎 2021-01-27 09:23

In my Java Project, hibernate.cfg.xml is sitting in the source folder-- \\src. So, to be precise, it is a file in the source folder, sitting right next to the

相关标签:
2条回答
  • 2021-01-27 10:14

    Exact same code-- both the calling class and DTOs worked in another project i set up from scratch. The setup & placement of libraries and the codes are the same, so are the other environment setting (all default Eclipse).

    The only difference is the DBs behind and the related config file settings. I used postgreSQL in the former one and set the related tags in config according to that. The DB in the second, the one that worked is MySQL. Outside of these related tags, the hibernate.cfg.xml file is the same in the two projects-- the exact same set of tags, and values of non-postgreSQL/non-MySQL properties.

    From what I know, Configure is a class reading & processing on the config file. and since everything else is the exact same, must be a mistake in postgreSQL setting in the former project.

    0 讨论(0)
  • 2021-01-27 10:20

    By default hibernate will look at hibernate.cfg.xml on your classpath root. If you're packaging a jar, this is typically right at the top level. For war, typically on WEB-INF/classes.

    If you eclipse is set with src folder as a source directory then it should be fine, just double check the generated war/jar has this file at correct location

    Try refreshing / cleaning your eclipse project as often the resource is out of sync with file system.

    Also have a look at Configuration class, it has configure(String) method to specify a custom location

    0 讨论(0)
提交回复
热议问题