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

后端 未结 3 1653
傲寒
傲寒 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 11:00

    Ok, I fixed my problem by forcing maven to put the hbm.xml files into the /target/classes/package/name folder, so at the end my pom looks like this:

    
        
            
                org.codehaus.mojo
                hibernate3-maven-plugin
                2.2
                
                    
                        hbm2cfgxml
                        generate-resources
                        
                            hbm2cfgxml
                        
                        false
                        
                            
                                
                                    hbm2cfgxml
                                    jdbcconfiguration
                                
                            
                            
                                package.name
                            
                        
                    
                    
                        hbm2hbmxml
                        generate-resources
                        
                            hbm2hbmxml
                        
                        false
                        
                            
                                
                                    hbm2hbmxml
                                    target/classes
                                
                            
                            
                                package.name
                            
                        
                    
                    
                        hbm2java
                        generate-sources
                        
                            hbm2java
                        
                        false
                        
                            
                                
                                    hbm2java
                                    configuration
                                
                            
                            
                                package.name
                                target/hibernate3/generated-mappings/hibernate.cfg.xml
                            
                        
                    
                    
                        hbm2dao
                        generate-sources
                        
                            hbm2dao
                        
                        false
                        
                            
                                
                                    hbm2dao
                                    configuration
                                
                            
                            
                                package.name
                                target/hibernate3/generated-mappings/hibernate.cfg.xml
                            
                        
                    
                
                
                    
                        postgresql
                        postgresql
                        8.4-701.jdbc3
                    
                
            
        
    
    

    And it works ok. As fas as I could see in other posts, in some early build phases those hbm.xml files should be copied from target/hibernate3/generated-mappings (where they are generated by default) to target/classes/package/name (where hibernate-tools looks for them), but in my case they aren't (which indicates I'm doing something wrong). So if there is anyone out there knowing what it might be I'm doing wrong, please tell me. Otherwise It'll have to suffice.

    There is one thing that isn't working: the package names aren't used in the generated POJOs and DAOs: but I created another thread for this here.

    Update: ok, now I finally got it. The problem with missing package names was in the hbm2hbmxml goal's configuration. I missed the componentProperties with packagename there, so the generated hbm.xml missed the fully classified class names. I updated the above pom, now it works fine. The issue regarding explicit copying the hbm.xml files to the target/classes folder is still the case, though.

提交回复
热议问题