aspose file tools*
The moose likes JBoss/WildFly and the fly likes Configuring a Postgres Datasource Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark "Configuring a Postgres Datasource" Watch "Configuring a Postgres Datasource" New topic
Author

Configuring a Postgres Datasource

Joe Trdinich
Greenhorn

Joined: Jun 10, 2003
Posts: 8
I'm trying to change the default datasource to Postgres. I'm using Jboss 3.2.1 with Postgres 7.3.2. So far I've made the following changes, and everything is still being sent to Hypersonic. Any help would be appreciated.
1. I added the jdbc postgres driver to /lib.
2. I added a postgres-ds.xml to /server/default/deploy, which contains the following:
<datasources>
<local-tx-datasource>
<depends>jboss:service=Postgres</depends>
<jndi-name>PostgresDS</jndi-name>
<connection-url>jdbc ostgresql://localhost:5432/JBOSS</connection-url>;
<driver-class>org.postgresql.Driver</driver-class>
<user-name>xxx</user-name>
<password>yyy</password>
<security-domain>PostgresDbRealm</security-domain>
</local-tx-datasource>

</datasources>
3. I changed standardjbosscmp-jdbc.xml in /server/default/conf, to have the following first two lines replaced:
<datasource>java:/PostgresDS</datasource>
<datasource-mapping>PostgreSQL</datasource-mapping>
4. Same thing in standardjaws.xml:
<datasource>java:/PostgresDS</datasource>
<type-mapping>PostgreSQL</type-mapping>
5. In login-config.xml, I added the following:
<application-policy name = "PostgresDbRealm">
<authentication>
<login-module code = "org.jboss.resource.security.ConfiguredIdentityLoginModule"
flag = "required">
<module-option name = "principal">xxx</module-option>
<module-option name = "userName">xxx</module-option>
<module-option name = "password">yyy</module-option>
<module-option name = "managedConnectionFactoryName">jboss.jca:service=LocalTxCM,name=PostgresDS</module-option>
</login-module>
</authentication>
</application-policy>
Darryl A. J. Staflund
Ranch Hand

Joined: Oct 06, 2002
Posts: 303
Hi there,
Try the following in order to configure a PostgreSQL datasource:
1. Deploy your PostgreSQL driver directly to the '/deploy' directory instead of the '/lib' directory.
2. Create a file named 'postgresql-ds.xml' that is structured as followed and deploy it to the '/deploy directory':

Darryl
Joe Trdinich
Greenhorn

Joined: Jun 10, 2003
Posts: 8
thanks for the reply. I did what you said, and here is some of the relevant output I got. The package is getting deployed, but everything is still being sent to Hypersonic.
10:52:37,647 INFO [MainDeployer] Starting deployment of package: file:/C:/jboss-3.2.1/server/default/deploy/hsqldb-ds.xml
10:52:38,418 INFO [HypersonicDatabase] Creating
10:52:38,418 INFO [HypersonicDatabase] Created
10:52:38,678 INFO [STDOUT] server.properties not found, using command line or default properties
10:52:38,678 INFO [STDOUT] Opening database: C:\jboss-3.2.1\server\default\data\hypersonic\default
10:52:38,678 INFO [STDOUT] HSQLDB server 1.7.1 is running
10:52:38,678 INFO [STDOUT] Use SHUTDOWN to close normally. Use [Ctrl]+[C] to abort abruptly
10:52:38,988 INFO [MainDeployer] Deployed package: file:/C:/jboss-3.2.1/server/default/deploy/hsqldb-ds.xml
10:52:38,988 INFO [MainDeployer] Starting deployment of package: file:/C:/jboss-3.2.1/server/default/deploy/postgres-ds.xml
10:52:39,499 INFO [MainDeployer] Deployed package: file:/C:/jboss-3.2.1/server/default/deploy/postgres-ds.xml

10:52:58,827 INFO [Template] Created table 'TEMPLATE' successfully.
10:52:58,957 INFO [Operator] Created table 'OPERATOR' successfully.
10:52:59,458 INFO [Terminal] Created table 'TERMINAL' successfully.
10:52:59,578 INFO [TerminalMsg] Created table 'TERMINALMSG' successfully.
10:52:59,618 INFO [OperatorTeam] Created table 'OPERATORTEAM' successfully.
10:52:59,628 INFO [OperatorTeam] Created table 'OPERATOR_OPERATORTEAM' successfully.
Darryl A. J. Staflund
Ranch Hand

Joined: Oct 06, 2002
Posts: 303
Hi there,
Judging from your output, you have both hsqldb-ds.xml and postgresql-ds.xml residing in your deploy directory. If you don't need the Hypoersonic datasource, rename the file or remove it from the deploy directory.
Darryl
Joe Trdinich
Greenhorn

Joined: Jun 10, 2003
Posts: 8
I tried that before, but put it back because I was getting the following. What all do I have to do to let jboss know to use PostgresDS rather than DefaultDS (hypersonic)?
org.jboss.deployment.DeploymentException: Error: can't find data source: java:/DefaultDS; - nested throwable: (javax.naming.NameNotFoundException: DefaultDS not bound)
at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCEntityBridge.<init>(JDBCEntityBridge.java:115)
...
[ObjectName: jboss.j2ee:jndiName=ejb/Template,service=EJB
state: FAILED
I Depend On:
Depends On Me: org.jboss.deployment.DeploymentException: Error: can't find data source: java:/DefaultDS; - nested throwable: (javax.naming.NameNotFoundException: DefaultDS not bound), ObjectName: jboss.j2ee:jndiName=ejb/Terminal,service=EJB
...
Joe Trdinich
Greenhorn

Joined: Jun 10, 2003
Posts: 8
That above error occurs when starting up the entity container.
Darryl A. J. Staflund
Ranch Hand

Joined: Oct 06, 2002
Posts: 303
If you want something quick and dirty, try modifying the name of the default database in conf/standardjboss-cmp.xml file. I wish I could offer more but my JBoss book at at another location and I have a lot on my plate this afternoon.
I also recommend searching the JBoss forums and see what you come up with. Everyone under the JBoss sun can be found there -- except actual up-to-date documentation!
Darryl
Joe Trdinich
Greenhorn

Joined: Jun 10, 2003
Posts: 8
Darryl: Thanks a lot for all your help so far.
I changed the default mapping in both standardjbosscmp-jdbc.xml and standardjaws.xml, yet it is still giving me that message. I can't for the life of me figure out where DefaultDS is being referenced. Any ideas?
Darryl A. J. Staflund
Ranch Hand

Joined: Oct 06, 2002
Posts: 303
Hi Joe,
If it is not important that your PostgreSQL database be the default connection per se, but only important that you establish a connection with your PostgreSQL database from within your application, try doing the following (NB: I am assuming you are using CMP here):

1. Create a PostgreSQL datasource but name it something different than DefaultDS.
2. At the very top of your jbosscmp-jdbc.xml file, add something similat to the following immediately after the opening tag (NB: The following is a snippet from my code. Modify it as appropriate):

It works for me!
Darryl
Joe Trdinich
Greenhorn

Joined: Jun 10, 2003
Posts: 8
I am now getting:
11:33:25,048 ERROR [URLDeploymentScanner] MBeanException: Exception in MBean operation 'checkIncompleteDeployments()'
Cause: Incomplete Deployment listing:
Packages waiting for a deployer:
<none>
Incompletely deployed packages:
<none>
MBeans waiting for classes:
<none>
MBeans waiting for other MBeans:
[ObjectName: jboss.j2ee:jndiName=ejb/Template,service=EJB
state: FAILED
I Depend On:
Depends On Me: org.jboss.deployment.DeploymentException: Error while fixing table name; - nested throwable: (org.jboss.util.NestedSQLException: Apparently wrong driver class specified for URL: class: org.postgresql.Driver, url: jdbc ostgresql://xxx:5432/JBOSS; - nested throwable: (org.jboss.resource.JBossResourceException: Apparently wrong driver class specified for URL: class: org.postgresql.Driver, url: jdbc ostgresql://xxx:5432/JBOSS)), ObjectName: jboss.j2ee:jndiName=ejb/Terminal,service=EJB
murali kankanala
Ranch Hand

Joined: Nov 15, 2004
Posts: 110
hi joe,

i have the problem in configuring the datasource for hsqldb in jboss

as u have the problem in configuring the datasource for postgresql


Already we are using the PostgreSQL database in our application

thanks a lot
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Configuring a Postgres Datasource