How to configure hibernate-tools with maven to generate hibernate.cfg.xml, *.hbm.xml, POJOs and DAOs

后端 未结 3 1648
傲寒
傲寒 2020-12-29 10:16

can any one tell me how to force maven to precede mapping .hbm.xml files in the automatically generated hibernate.cfg.xml file with package path?

My general idea is,

3条回答
  •  再見小時候
    2020-12-29 10:37

    how can I configure hbm2cfgxml so that hibernate.cfg.xml looks like below (...)

    I have a project that is using hbm2cfgxml and the entries do reflect the packagename in the path to the hbm.xml. So there is clearly something wrong on your side. Here are a few remarks:

    • I would bind hbm2cfgxml on the generate-resources phase, you're not generating sources
    • I wouldn't generate the file in src/main/resources but in target/classses (why do you put generated stuff in the source tree, you want a clean to clean it).
    • There is a typo, it's configurationfile, not configurationFile but...
    • Why the hell do you have a in the configuration of hbm2cfgxml? You want to generate it here... I would remove it.

    Update: You should put the informations required to connect to the database in src/main/resources/database.properties (that's the default value of the propertyfile property), not in src/main/resources/hibernate.cfg.xml (remove that file). Below a sample database.properties:

    hibernate.connection.driver_class=org.apache.derby.jdbc.ClientDriver
    hibernate.connection.url=jdbc:derby://localhost:1527//home/pascal/Projects/derbyDBs/EMPLDB
    hibernate.connection.username=APP
    hibernate.connection.password=APP
    hibernate.dialect=org.hibernate.dialect.DerbyDialect
    

    And as I said, remove the src/main/resources/hibernate.cfg.xml file, you want to generate it.

    is there a way to tell maven to copy resources to the target folder before executing hbm2java? (...)

    The hbm2java goal Invokes the execution of the lifecycle phase process-resources prior to executing itself (from the documentation). So that's the default behavior and occurs with hibernate3:hbm2java or generate-sources if hbm2java is bound to it.

提交回复
热议问题