Thanks for using OpenJPA and the users alias. Good luck.
Craig
On Jan 21, 2010, at 7:35 PM, wang yu wrote:
Craig,
I have tested it. It's cool!
The db connection will be returned into pool and I can reuse the
JPAEntityManager!
Thanks again.
Regards,
Yu Wang
On Fri, Jan 22, 2010 at 9:57 AM, wang yu <[email protected]> wrote:
Craig:
Thank you for your quick response.
If I close it, the connection will be returned into pool or just
destroyed?
Regards,
Yu Wang
On Thu, Jan 21, 2010 at 8:56 PM, Craig L Russell <[email protected]
> wrote:
Hi Yu Wang,
You need to tell OpenJPA that you're not using the Connection any
more by
calling close(). See this Example 4.4 in the user's manual:
import java.sql.*;
import org.apache.openjpa.persistence.*;
... OpenJPAEntityManager kem = OpenJPAPersistence.cast(em);
Connection conn = (Connection) kem.getConnection();
// do JDBC stuff
conn.close();
Regards,
Craig
On Jan 21, 2010, at 1:26 AM, wang yu wrote:
Gurus:
I use OpenJPA 1.2.1 and dbcp:
<property
name="openjpa.ConnectionDriverName"
value="org.apache.commons.dbcp.BasicDataSource" />
<property
name="openjpa.ConnectionProperties"
value="driverClassName=oracle.jdbc.driver.OracleDriver,
url=jdbc:oracle:thin:@localhost:1521:orcl, username=XXXX,
password=XXX, maxActive=8, maxWait=10000,
poolPreparedStatements=true"
/>
And I found the connection pool worked perfect for JPA query. But
if I
use JDBC query like following:
OpenJPAEntityManager open_manager =
OpenJPAPersistence
.cast(entitiManager);
Connection conn = (Connection)
open_manager.getConnection();
java.sql.PreparedStatement PrepStmt = null;
java.sql.ResultSet sqlResults = null;
try {
PrepStmt = connection
.prepareStatement("select
* from
tsam.MON_BRIDGE");
sqlResults = PrepStmt.executeQuery();
} catch (SQLException e) {
log.error(e.getMessage());
} finally {
try {
if (sqlResults != null)
sqlResults.close();
if (PrepStmt != null)
PrepStmt.close();
} catch (SQLException e) {
}
}
The connection cannot be put into pool and the result is out of db
connection.
How should I do? Should I use createNativeQuery(String sql, Class
resultClass) to query with native sql?
Regards,
Yu Wang
Craig L Russell
Architect, Sun Java Enterprise System http://db.apache.org/jdo
408 276-5638 mailto:[email protected]
P.S. A good JDO? O, Gasp!
Craig L Russell
Architect, Sun Java Enterprise System http://db.apache.org/jdo
408 276-5638 mailto:[email protected]
P.S. A good JDO? O, Gasp!