How can I set Datasource when I'm creating Hibernate SessionFactory?

后端 未结 8 416
星月不相逢
星月不相逢 2020-12-02 17:17

I\'m creating SessionFactory and I have my datasource as object in code where I\'m creating SessionFactory, but i cannot set datasource to Hibernate Configuration object. So

8条回答
  •  不思量自难忘°
    2020-12-02 18:19

    If you are using Spring framework, then use LocalSessionFactoryBean for injecting your data source to Hibernate SessionFactory.

    
        
                
                 
        
    
    
        
            
                org.postgresql.Driver
            
            
                jdbc:postgresql://localhost/yourdb
            
            
                postgres
            
            
                postgres
                 
        
    
        
            
                
                 
            
                
                    conf/hibernate/UserMapping.hbm.xml               
                
            
            
                
                     org.hibernate.dialect.PostgreSQLDialect       
                    update
                     true 
                    true
                
            
        
    
    

提交回复
热议问题