-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Using a User Defined JDBC connection
PostPosted: Wed Aug 18, 2004 2:26 pm 
Newbie

Joined: Wed Aug 18, 2004 2:07 pm
Posts: 1
I am trying to use hibernate with a pre existing JDBC pool by creating a connection and passing it the url of the pool, then using the connection to create a session object, just like the example in the documentation. However, I get the exception below. I have traced through the exception and found that the getConnection method of the UserSuppliedConnectionProvider only returns the exception I got below.
I am guessing this has something to do with needing a properties file, but was hoping I would just be able to supple the jdbc pool url like the documentation described.
Any thoughts would be greatly appreciated, thanks in advance.

Let me know if any more information is needed...

Hibernate version: 2.1.6

Mapping documents:
<hibernate-mapping>

<class name="com.urbancode.website.product.Product" table="PRODUCTS" >
<id name="id" column="id" type="java.lang.Long" unsaved-value="0">
<generator class="native"/>
</id>
<property name="productName" column="PRODUCT_NAME" type="java.lang.String" />
<property name="productURL" column="PRODUCT_URL" type="java.lang.String" />
<property name="version" column="VERSION" type="java.lang.String" />
<property name="description" column="DESCRIPTION" type="java.lang.String" />
<property name="status" column="STATUS" type="java.lang.String" />
<property name="cost" column="COST" type="java.math.BigDecimal" />
</class>

</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
public void service(HttpServletRequest request, HttpServletResponse response) {
Session session = null;

String rb_name = ActionThreadLocalHelper.getCms().getConfigurations().getString("resourcebroker");
String url = ActionThreadLocalHelper.getCms().getConfigurations().getString("resourcebroker." + rb_name + ".pool");

try {
Connection connection = DriverManager.getConnection(url);
session = ConnectionFactory.getInstance().getSession(connection);
}
catch (Exception e) {
// TODO properly handle this exception
//throw new PersistenceException(e);
}
if(session != null) {
HibernateSessionHelper.setCurrentSession(session);
}
else {
// TODO alert user that they did not get the session
}
try {
service0(request, response);
}
catch (Exception e1) {
// TODO properly handle this exception
e1.printStackTrace();
}
finally {
try {
HibernateSessionHelper.closeCurrentSession();
} catch (PersistenceException e2) {
// TODO Handle this exception properly
}
}

}

//--------------------------------------------------------------------------
public Session getSession(Connection connection) throws HibernateException {
Session session = sessionFactory.openSession(connection);
return session;
}

//--------------------------------------------------------------------------
public void insertProduct(Product product)
throws PersistenceException {

Session session = null;

try {
session = HibernateSessionHelper.getCurrentSession();
session.save(product);
session.flush();
}
catch (Exception e) {
throw new PersistenceException(e);
}
}

//--------------------------------------------------------------------------
public void service0(HttpServletRequest request,
HttpServletResponse response)
throws Exception {

Product product = null;

String productName = (String) request.getParameter("productName");
String productURL = (String) request.getParameter("productURL");
String version = (String) request.getParameter("version");
String cost = (String) request.getParameter("cost");
String description = (String) request.getParameter("description");
String status = (String) request.getParameter("status");

if (productName == null || productName.equals("") ||
productURL ==null || productURL.equals("") ||
version == null || version.equals("") ||
cost == null || cost.equals("") ||
description == null || description.equals("")) {

}

//product = new Product(productName, productURL, version, description, new BigDecimal(cost), status);
product = new Product("Anthill Pro", "/default.jsp", "1.0", "Nifty keen and cool", new BigDecimal("1234"), "Inactive");

try {
ProductHelper.getInstance().insertProduct(product);
}
catch (PersistenceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

try {
forward(HibernateAction.C_ACTION_PATH);
} catch (CmsException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
Full stack trace of any exception that occurs:
com.urbancode.website.database.PersistenceException: java.lang.UnsupportedOperationException: The
user must supply a JDBC connection
at com.urbancode.website.product.ProductHelper.insertProduct(ProductHelper.java:142)
at com.urbancode.website.product.web.ProductAction.service0(ProductAction.java:58)
at com.urbancode.website.product.web.HibernateAction.service(HibernateAction.java:65)
at com.opencms.launcher.CmsActionLauncher.launch(CmsActionLauncher.java:68)
at com.opencms.launcher.A_CmsLauncher.initlaunch(A_CmsLauncher.java:274)
at com.opencms.core.OpenCms.showResource(OpenCms.java:961)
at com.opencms.core.OpenCmsHttpServlet.doGet(OpenCmsHttpServlet.java:310)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChai
n.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:1
57)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104 )
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java :198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104 )
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104 )
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102 )
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104 )
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http 11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)
Caused by: java.lang.UnsupportedOperationException: The user must supply a JDBC connection
at net.sf.hibernate.connection.UserSuppliedConnectionProvider.getConnection(UserSuppliedC onnectionProvider.java:32)
at net.sf.hibernate.impl.BatcherImpl.openConnection(BatcherImpl.java:278)
at net.sf.hibernate.id.TableGenerator.generate(TableGenerator.java:81)
at net.sf.hibernate.id.TableHiLoGenerator.generate(TableHiLoGenerator.java:59)
at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:765)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:738)
at com.urbancode.website.product.ProductHelper.insertProduct(ProductHelper.java:138)
... 32 more


Name and version of the database you are using:
mysql Ver 12.22 Distrib 4.0.20, for pc-linux (i686)

Debug level Hibernate log excerpt:


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.