使用JPA persistence.xml报错:A ResourcePool could not acquire a resource from its primary factory or sour

使用JPA persistence.xml 配置时,报错:

Unable to acquire JDBC Connection

Caused by: java.sql.SQLException: Connections could not be acquired from the underlying database!

Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.

首先检查persistence.xml中url,driver,username,password的写法是否正确,我是直接把hibernate.cfg.xml下面的拷贝过来的,所以写错了,对比如下:

hibernate:

jdbc:mysql://localhost:3306/hibernate
com.mysql.jdbc.Driver
root
123456

JPA:




注意driver_class 变为driver,username变为user,还有前缀也要变为 javax.persistence.jdbc,最后附上正确的persistence.xml



    
        
        
    
        
        org.hibernate.jpa.HibernatePersistenceProvider
        
        domain.CstCustomer
        domain.CstLinkman

        
        
        
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            

        
    

 

你可能感兴趣的:(JAVA,Hibernate)