线程" main"中的Hibernate程序异常org.hibernate.exception.GenericJDBCException:无法打开连接

时间:2017-04-24 20:55:46

标签: java hibernate

以下是我正在测试并获取错误的Hibernate程序

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment). 
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.hibernate.exception.GenericJDBCException: Cannot open connection
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:420)
at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144)
at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:129)
at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:57)
at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1290)
at test.Client.main(Client.java:31)
Caused by: java.sql.SQLException: ORA-01017: invalid username/password; logon denied

at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:450)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:392)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:385)
at oracle.jdbc.driver.T4CTTIfun.processError(T4CTTIfun.java:1018)
at oracle.jdbc.driver.T4CTTIoauthenticate.processError(T4CTTIoauthenticate.java:501)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:522)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:257)
at oracle.jdbc.driver.T4CTTIoauthenticate.doOAUTH(T4CTTIoauthenticate.java:437)
at oracle.jdbc.driver.T4CTTIoauthenticate.doOAUTH(T4CTTIoauthenticate.java:954)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:639)
at oracle.jdbc.driver.PhysicalConnection.connect(PhysicalConnection.java:666)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:566)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:417)
... 5 more

下面是Bean UserDetails.java类

package beans;



public class UserDetails {


private int userId;
private String userName;
private String userAddress;
private String userEmail;
private int userPhoneNo;
private String userPassword;

public int getUserId() {
    return userId;
}
public String getUserPassword() {
    return userPassword;
}
public void setUserPassword(String userPassword) {
    this.userPassword = userPassword;
}
public void setUserId(int userId) {
    this.userId = userId;
}
public String getUserName() {
    return userName;
}
public void setUserName(String userName) {
    this.userName = userName;
}
public String getUserAddress() {
    return userAddress;
}
public void setUserAddress(String userAddress) {
    this.userAddress = userAddress;
}
public String getUserEmail() {
    return userEmail;
}
public void setUserEmail(String userEmail) {
    this.userEmail = userEmail;
}
public int getUserPhoneNo() {
    return userPhoneNo;
}
public void setUserPhoneNo(int userPhoneNo) {
    this.userPhoneNo = userPhoneNo;
}


}

以下是映射UserDetails.hbm.xml文件

<!DOCTYPE hibernate-mapping PUBLIC 
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<hibernate-mapping>

<class name="beans.UserDetails" table="User">
<id name="userId" column="UID" />

<property name="userName"></property>
<property name="userAddress"></property>
<property name="userEmail"></property> 
<property name="userPhoneNo"></property>
<property name="userPassword"></property>

</class>

</hibernate-mapping>

下面是hibernate.cfg.xml文件

<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">


<hibernate-configuration>

<session-factory>

<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:ORCL</property>
<property name="hibernate.conection.username">system</property>
<property name="hibernate.connection.password">system</property>
<property name="hibernate.conection.pool-size">1</property>

<property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
<property name="hbm2ddl.auto">update</property>
<property name="show-sql">true</property>

<mapping resource="resources/UserDetails.hbm.xml"/>


</session-factory>

</hibernate-configuration>

以下是Test类Client.java

package test;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

import beans.UserDetails;

public class Client {

public static void main(String[] args) {

    UserDetails ud=new UserDetails();
    ud.setUserId(100);
    ud.setUserName("ABC");
    ud.setUserAddress("ABCDEF");
    ud.setUserEmail("ABC@gmail.com");
    ud.setUserPassword("12345");
    ud.setUserPhoneNo(98765);

    Configuration cfg=new Configuration();
    cfg.configure("resources/hibernate.cfg.xml");

    //System.out.println("Configure complete");

    SessionFactory sf=cfg.buildSessionFactory();
    Session s=sf.openSession();

    s.save(ud);

    s.beginTransaction().commit();

    sf.close();



}

}

我已经使用一个简单的JDBC程序检查了相同的细节,程序运行成功。

请您告诉我Hibernate程序的问题。 在此先感谢。

0 个答案:

没有答案