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("csdn@sina.com");
		session.getTransaction().commit();
		session.close();
		System.out.println("结束");
	}
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值