How to configure maven hbm2hbmxml and hbm2java to run one after the other in mvn clean install

前端 未结 6 1376
一向
一向 2020-12-05 12:37

I need to be able to call mvn clean install and have maven call hibernate3:hbm2hbmxml to generate the mapping files from a database and after than call hbm2java to get the J

6条回答
  •  攒了一身酷
    2020-12-05 13:02

    Neither of the two answers worked for me out of the box. After a bit of research, I was able to generate POJOs from a database. Hope this fast tracks someone.

    Simply generate the java files - no mapping files generated.

    Define your database connection in src/test/resources/reveng/hibernate.cfg.xml. Using the test branch so these files are not copied into the distributable artifact.

    
    
    
        
            oracle.jdbc.driver.OracleDriver
            
            jdbc:oracle:thin:@server.domain.com:1521:catalog
            login
            ****
            PM
        
    
    

    Create a list of tables you want to import. Again in the test branch: src/test/resources/reveng/model.reveng.xml

    
    
    
    
      
      
      
      
      
      
    
    

    Add the hibernate3 maven plugin to your pom

    
      
        ...
        
          org.codehaus.mojo
          hibernate3-maven-plugin
          2.2
          
            
              
                hbm2java
                src/main/java/com/me/examples/pm/data
                jdbcconfiguration
              
            
            
              
              src/test/resources/reveng/model.reveng.xml
              src/test/resources/reveng/hibernate.cfg.xml
              true
              true
            
          
          
            
              com.oracle
              classes12
              10.2.0.1.0
            
            
              cglib
              cglib-nodep
              2.1_3
            
          
        
      
    
    

    Run maven

    mvn hibernate3:hbm2java
    

提交回复
热议问题