关于 The user must supply a JDBC connection,搞了好几天了

CNSDYT 2005-06-19 08:34:03
java.lang.UnsupportedOperationException: The user must supply a JDBC connection
at net.sf.hibernate.connection.UserSuppliedConnectionProvider.getConnect
ion(UserSuppliedConnectionProvider.java:32)
at net.sf.hibernate.impl.BatcherImpl.openConnection(BatcherImpl.java:289
)
at net.sf.hibernate.impl.SessionImpl.connect(SessionImpl.java:3361)
at net.sf.hibernate.impl.SessionImpl.connection(SessionImpl.java:3321)
at net.sf.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.ja
va:40)
at net.sf.hibernate.transaction.JDBCTransactionFactory.beginTransaction(
JDBCTransactionFactory.java:19)
at net.sf.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:2
251)
at myutil.WLSStartup.doBind(WLSStartup.java:79)
at myutil.WLSStartup.startup(WLSStartup.java:47)
at weblogic.t3.srvr.StartupClassService.invokeStartup(StartupClassServic
e.java:158)
at weblogic.t3.srvr.StartupClassService.invokeClass(StartupClassService.
java:139)
at weblogic.t3.srvr.StartupClassService.access$0(StartupClassService.jav
a:130)
at weblogic.t3.srvr.StartupClassService$1.run(StartupClassService.java:1
02)
at weblogic.security.service.SecurityServiceManager.runAs(SecurityServic
eManager.java:780)
at weblogic.t3.srvr.StartupClassService.invokeStartupClass(StartupClassS
ervice.java:97)
at weblogic.t3.srvr.StartupClassService.resume(StartupClassService.java:
76)
at weblogic.t3.srvr.ServerLifeCycleList.resume(ServerLifeCycleList.java:
67)
at weblogic.t3.srvr.T3Srvr.resume(T3Srvr.java:832)
at weblogic.t3.srvr.T3Srvr.run(T3Srvr.java:300)
...全文
515 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
CNSDYT 2005-06-20
  • 打赏
  • 举报
回复
搞定了,原来是数据源的命名问题
http://spaces.msn.com/members/mikeqin/Blog/cns!1pIgyp3FBi35f0vt8imu3HYQ!300.entry?owner=1
UPCCPU 2005-06-19
  • 打赏
  • 举报
回复
你的sessionFactory 怎么那样来取呢?不需自己来查询jndi的
通过配置文件Hibernate就会给你产生sessionFactory 了,一般使用一下面一个语句就可以了
sessionFactory = new Configuration().configure().buildSessionFactory();
try {
Context ctx = new InitialContext();
sessionFactory = (SessionFactory) ctx.lookup("hibernate");
//cfg.configure(CONFIG_FILE_LOCATION);
//sessionFactory = cfg.buildSessionFactory();
}
这一段换成
try{
sessionFactory = new Configuration().configure().buildSessionFactory();

}
CNSDYT 2005-06-19
  • 打赏
  • 举报
回复
调用jndi
public static Session currentSession() throws HibernateException {
Session session = (Session) threadLocal.get();

if (session == null) {
if (sessionFactory == null) {
try {
Context ctx = new InitialContext();
sessionFactory = (SessionFactory) ctx.lookup("hibernate");
//cfg.configure(CONFIG_FILE_LOCATION);
//sessionFactory = cfg.buildSessionFactory();
}
catch (Exception e) {
System.err.println("%%%% Error Creating SessionFactory %%%%");
e.printStackTrace();
}
}
session = sessionFactory.openSession();
threadLocal.set(session);
}

return session;
}
CNSDYT 2005-06-19
  • 打赏
  • 举报
回复
配置文件
<property name="dialect">
net.sf.hibernate.dialect.SQLServerDialect
</property>
<!-- <property name="connection.provider_class">net.sf.hibernate.connection.DatasourceConnectionProvider</property>-->
<property name="connection.datasource">
java:/comp/env/jdbc/mydatasource
</property>
<property name="connection.driver_class">
com.microsoft.jdbc.sqlserver.SQLServerDriver
</property>
CNSDYT 2005-06-19
  • 打赏
  • 举报
回复
调用jndi,已经把hibernate 成功的绑定到了jndi上了,如下:
Bind Name: hibernate
Object Class: net.sf.hibernate.impl.SessionFactoryImpl
Object Hash Code: 4669345
Object To String: net.sf.hibernate.impl.SessionFactoryImpl@473fa1

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧