Page 1 of 1

Broadleaf Commerce with DB2 backend

Posted: Tue Jan 24, 2012 10:15 pm
by rgendler
Hi,

Does the framework currently supports DB2 persistence ? I've set up a project using your provided Maven Archetype package. It works fine with default HSQL setup. However when I tried to do it with DB2 - it fails to deploy. The problem seems to be in Jetty environment DBCP configuration, but I am not 100% sure. The exception that appears in Jetty output is:

[artifact:mvn] [ INFO] 18:49:57 ConnectionProviderFactory - Initializing connection provider: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider
[artifact:mvn] [ INFO] 18:49:57 InjectedDataSourceConnectionProvider - Using provided datasource
[artifact:mvn] [ WARN] 18:49:57 SettingsFactory - Could not obtain connection to query metadata
[artifact:mvn] org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory ([jcc][t4][2030][11211][4.2.73] A communication error occurred during operations on the connection's underlying socket, socket input stream,
[artifact:mvn] or socket output stream. Error location: Reply.fill(). Message: Insufficient data. ERRORCODE=-4499, SQLSTATE=08001)
[artifact:mvn] at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1225)
[artifact:mvn] at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
[artifact:mvn] at org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider.getConnection(InjectedDataSourceConnectionProvider.java:71)
[artifact:mvn] at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:113)
[artifact:mvn] at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2863)
[artifact:mvn] at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2859)
[artifact:mvn] at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1870)
[artifact:mvn] at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:906)
[artifact:mvn] at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:74)
[artifact:mvn] at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:225)

I am not sure if some additional configuration needs to be added to jetty-env.xml
The version of DB2 is 9.7

Re: Broadleaf Commerce with DB2 backend

Posted: Wed Jan 25, 2012 10:50 am
by bpolster
The framework is based on JPA and Hibernate which both claim to support DB2 persistence. The error below seems to indicate that you are unable to connect. Here are a few Broadleaf specific items to verify.

1. Make sure the DB2 required jars are available to your project. (typically by adding the dependency to pom.xml)
2. Update DB connection settings in all BLC required files. The exact files differ by version, but search for BasicDataSource in your xml files and you'll find the relevant locations.
3. As part of number 2, you'll be specifying the db name and user information. Make sure to create that database within db2 and that the user has rights to create tables (BLC attempts to create the tables on startup of the demo and Archetype applications).

You may see additional DB2 specific issues after you are successfully connected and we'll help you through those, but the first step is to get connected to your DB2 instance.

Re: Broadleaf Commerce with DB2 backend

Posted: Thu Jan 26, 2012 8:37 pm
by rgendler
Hi


I am still seeing the similar problem. I've modified applicationContext*.xml files with DB2 connection settings and modified pom files with DB2 drivers dependencies.
I do see the database schema loaded and have tables with data in my db instance.

However when I try to run the app with "ant jetty-demo" I am still seeing

[artifact:mvn] [ WARN] 15:30:09 SettingsFactory - Could not obtain connection to query metadata
[artifact:mvn] org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory ([jcc][t4][2030][11211][4.2.73] A communication error occurred during operations on the connection's underlying socket, socket input stream,
[artifact:mvn] or socket output stream. Error location: Reply.fill(). Message: Insufficient data. ERRORCODE=-4499, SQLSTATE=08001)
[artifact:mvn] at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1225)
[artifact:mvn] at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
[artifact:mvn] at org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider.getConnection(InjectedDataSourceConnectionProvider.java:71)
[artifact:mvn] at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:113)
[artifact:mvn] at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2863)
[artifact:mvn] at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2859)
[artifact:mvn] at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1870)
[artifact:mvn] at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:906)
[artifact:mvn] at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:74)
[artifact:mvn] at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:225)
.........

Is this a jetty config issue ? I did modify jetty-env.xml that came with the project, but it does not seem to have ay effect.

Thanks.

Re: Broadleaf Commerce with DB2 backend

Posted: Fri Jan 27, 2012 4:17 pm
by rgendler
Hi,

I did get the application started with DB2 backend.

Here are the settings to do so:

applicationContext*.xml Spring descriptors must define datasources in the form:

<bean id="webDS" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.ibm.db2.jcc.DB2Driver" />
<property name="url" value="jdbc:db2://<db_server_host>:<db_server_port>/<your_db_instance>" />
<property name="username" value="<login_name>" />
<property name="password" value="<login_password>" />
</bean>

You have to make sure that DB credentials supplied above have sufficient privileges to create DB schema for the specified db instance.

persistence-*-store-*.xml files should define persistence units in the form:

<persistence-unit name="blPU" transaction-type="RESOURCE_LOCAL">
<non-jta-data-source>jdbc/web</non-jta-data-source>
<exclude-unlisted-classes/>
<properties>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.DB2Dialect"/>
<property name="hibernate.show_sql" value="false"/>
</properties>
</persistence-unit>

the DB2Dialect must be specified.


pom files must contain dependencies for the DB2 JDBC driver.
Something like this:

<dependency>
<groupId>com.ibm.db2</groupId>
<artifactId>db2-native</artifactId>
<version><your_version></version>
</dependency>
<dependency>
<groupId>com.ibm.db2</groupId>
<artifactId>db2-jcc4</artifactId>
<version><your_version></version>
</dependency>
<dependency>
<groupId>com.ibm.db2</groupId>
<artifactId>db2-sqlj4</artifactId>
<version><your_version></version>
</dependency>
<dependency>
<groupId>com.ibm.db2</groupId>
<artifactId>db2-db2java</artifactId>
<version><your_version></version>
</dependency>

IBM does not offer it's JDBC drivers in free Maven repositories. Most likely you would need to add these files to your private Maven repository or acces them directly from the file system.
Depending on a version of the database your dependency settings may be different.

Re: Broadleaf Commerce with DB2 backend

Posted: Mon Jan 30, 2012 12:53 am
by bpolster
Thanks for the post. One caution, we did find an area within BLC that was generating a column name longer than 30 characters that was causing an issue in other DBMSs. We've patched that with the latest 1.6.0_SNAPSHOT and in 1.5.2-GA.