天天看點

No connection properties specified - the user must supply JDBC connections 的解決辦法

照hibernate官網的例子寫了一下,

其中setProperty時是按xml時寫的那種縮寫比如hibernate.dialect 寫成dialect

hibernate.connection.username寫成connection.username

這樣會提示

(0 ms) [main] WARN : org.hibernate.connection.UserSuppliedConnectionProvider

#configure : No connection properties specified - the user must supply JDBC connections

正确的是按hibernate手冊裡把屬性名寫全了就沒事了

package configuration;

import hibernate.Person;

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

public class ConfigurationTest {

	public static void main(String[] args) {
		Configuration cfg = new Configuration()
		.addClass(hibernate.DocumentType.class)
		.addClass(hibernate.Person.class)
		.setProperty("hibernate.dialect", "org.hibernate.dialect.Oracle10gDialect")
		.setProperty("current_session_context_class", "thread")
		.setProperty("hibernate.connection.url", "jdbc:oracle:thin:localhost:1521:orcl")
		.setProperty("hibernate.connection.username", "sj")
		.setProperty("hibernate.connection.password", "123456")
		.setProperty("hibernate.connection.driver_class", "oracle.jdbc.driver.OracleDriver")
		.setProperty("show_sql", "true")
		.setProperty("hbm2ddl.auto", "update")
		.setProperty("hibernate.connection.pool_size", "1")
		.setProperty("hbm2ddl.auto", "update")
		.setProperty("cache.provider_class", "org.hibernate.cache.NoCacheProvider");
		SessionFactory sessions = cfg.buildSessionFactory();
		Session session = sessions.openSession();
		session.beginTransaction();		
		Person person = (Person)session.load(Person.class, new Long(1));
		person.getEmails().add("[email protected]");
		session.getTransaction().commit();
		session.close();
		System.out.println("結束");
	}
}
           

繼續閱讀