c3p0 vs JPA injections on JBoss

View: New views
3 Messages — Rating Filter:   Alert me  

c3p0 vs JPA injections on JBoss

by Jakub Danilewicz :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I am struggling with the following problem. I am trying to transparently replace the standard JBoss 4.2.1.GA pooling system with the c3p0 implementation.


Since the EAR applications make use of JPA framework to access a Postgres 8.2.4 database, their typical "persistence.xml" looks like this:

<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
                    version="1.0">
    <persistence-unit name="my-unit">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <jta-data-source>jdbc/my-ds</jta-data-source>
        <jar-file>../lib/my-jar.jar</jar-file>
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
            <property name="cache.use_query_cache" value="true" />
        </properties>
    </persistence-unit>
</persistence>


However, when I try to define the equivalent c3p0-based data source by replacing the standard "postgres-ds.xml" with the following "c3p0-service.xml"

<?xml version="1.0" encoding="UTF-8"?>
<server>
    <mbean code="com.mchange.v2.c3p0.jboss.C3P0PooledDataSource" name="jboss:service=C3P0PooledDataSource">
        <attribute name="JndiName">jdbc/my-ds</attribute>
        <attribute name="JdbcUrl">jdbc:postgresql://localhost:5432/my-db</attribute>
        <attribute name="DriverClass">org.postgresql.Driver</attribute>
        <attribute name="User">...</attribute>
        <attribute name="Password">...</attribute>
        <depends>jboss:service=Naming</depends>
    </mbean>
</server>


the JPA dependency injections (i.e. @PersistenceContent (unitName="my-unit")) cease to work.

--- MBeans waiting for other MBeans ---
ObjectName: jboss.j2ee:ear=my-app.ear,jar=my-app-ejb.jar,name=MyServiceBean,service=EJB3
  State: NOTYETINSTALLED
  I Depend On:
    persistence.units:ear=my-app.ear,unitName=my-unit
ObjectName: persistence.units:ear=my-app.ear,unitName=my-unit
  State: NOTYETINSTALLED
  I Depend On:
    jboss.jca:name=jdbc/my-ds,service=DataSourceBinding
  Depends On Me:
    jboss.j2ee:ear=my-app.ear,jar=my-app-ejb.jar,name=MyServiceBean,service=EJB3
--- MBEANS THAT ARE THE ROOT CAUSE OF THE PROBLEM ---
ObjectName: jboss.jca:name=jdbc/my-ds,service=DataSourceBinding
  State: NOTYETINSTALLED
  Depends On Me:
    persistence.units:ear=my-app.ear,unitName=my-unit


It is a bit strange since the JBoss log shows that the data source is created properly.

12:35:22,109 INFO  [C3P0Registry] Initializing c3p0-0.9.1 [built 16-January-2007 14:46:42; debug? true; trace: 10]
12:35:22,203 INFO  [C3P0PooledDataSource] Bound C3P0 PooledDataSource to name 'jdbc/my-ds'. Starting...
12:35:22,265 INFO  [AbstractPoolBackedDataSource] Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> 1hge45l81yjhdnx17m9pic|7d2796, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> org.postgresql.Driver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 1hge45l81yjhdnx17m9pic|7d2796, idleConnectionTestPeriod -> 0, initialPoolSize -> 3, jdbcUrl -> jdbc:postgresql://localhost:5432/my-db, lastAcquisitionFailureDefaultUser -> null, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 0, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 15, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 3, numHelperThreads -> 3, numThreadsAwaitingCheckoutDefaultUser -> 0, preferredTestQuery -> null, properties -> {user=******, password=******}, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false ]


Moreover, I have tried both 0.9.1 and 0.9.1.2 versions of the c3p0 library with the same result.

Maybe c3p0 data sources do not support JPA injections, maybe there is a particular Hibernate or JBoss library required to make it all working, I do not know. I do hope that you know what is wrong with this setting. :)


I am looking forward to any response.

Cheers,

Jakub

PS
It seems that I am not the only one that faces this issue:

http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3983368#3983368

------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
is a gathering of tech-side developers & brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing, &
iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian
Group, R/GA, & Big Spaceship. http://www.creativitycat.com 
_______________________________________________
c3p0-users mailing list
c3p0-users@...
https://lists.sourceforge.net/lists/listinfo/c3p0-users

Re: c3p0 vs JPA injections on JBoss

by vic@myoffice24x7 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Jakub

While datasource is created, it is not registered under "jboss.jca:name". Check your jmx-console.

To workaround the problem you will have to modify your -service.xml mbean definition, to something like this:
<mbean code="com.mchange.v2.c3p0.jboss.C3P0PooledDataSource"
  name="jboss.jca:service=DataSourceBinding,name=jdbc/my-ds">
// the rest is the same
</mbean>

We also found that mbean definitions shall be different for EJB2 and EJB3 styles.
An extract of our migration manuals for liferay portal / jboss platform is published here:
How To Implement c3p0 Pool For Liferay/Jboss bundle

I hope, it will help you to address the issue.

Regards
Victor

Jakub Danilewicz wrote:
I am struggling with the following problem. I am trying to
transparently replace the standard JBoss 4.2.1.GA pooling system with
the c3p0 implementation.
...
the JPA dependency injections (i.e. @PersistenceContent
(unitName="my-unit")) cease to work.

jboss.j2ee:ear=my-app.ear,jar=my-app-ejb.jar,name=MyServiceBean,service=EJB3
--- MBEANS THAT ARE THE ROOT CAUSE OF THE PROBLEM ---
ObjectName: jboss.jca:name=jdbc/my-ds,service=DataSourceBinding
  State: NOTYETINSTALLED
  Depends On Me:
    persistence.units:ear=my-app.ear,unitName=my-unit


It is a bit strange since the JBoss log shows that the data source is
created properly.

12:35:22,109 INFO  [C3P0Registry] Initializing c3p0-0.9.1 [built
16-January-2007 14:46:42; debug? true; trace: 10]
12:35:22,203 INFO  [C3P0PooledDataSource] Bound C3P0 PooledDataSource
to name 'jdbc/my-ds'. Starting...

Moreover, I have tried both 0.9.1 and 0.9.1.2 versions of the c3p0
library with the same result.

Maybe c3p0 data sources do not support JPA injections, maybe there is a
particular Hibernate or JBoss library required to make it all working,
I do not know. I do hope that you know what is wrong with this setting.
:)


I am looking forward to any response.

Re: c3p0 vs JPA injections on JBoss

by Jakub Danilewicz :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

vic@myoffice24x7 escribió:

> Hi Jakub
>
> While datasource is created, it is not registered under "jboss.jca:name".
> Check your jmx-console.
>
> To workaround the problem you will have to modify your -service.xml mbean
> definition, to something like this:
> <mbean code="com.mchange.v2.c3p0.jboss.C3P0PooledDataSource"
>   name="jboss.jca:service=DataSourceBinding,name=jdbc/my-ds">
> // the rest is the same
> </mbean>
>
>  
Thanks a lot - it works like a charm! :)

j-d

------------------------------------------------------------------------------
_______________________________________________
c3p0-users mailing list
c3p0-users@...
https://lists.sourceforge.net/lists/listinfo/c3p0-users