[jboss-user] [JBoss Seam] - How to modify the messages example to connect to Oracle DB
MonkeyKnifeFight
do-not-reply at jboss.com
Thu Feb 1 16:32:01 EST 2007
Hey guys another newbie question here. I'm trying to modify the messages example to connect to an Oracle database, then execute a simple query and display the results in a table. I'm having problems getting my configuration set up correctly. I added a -ds.xml file and edited the persistence.xml file to point to that datasource. Then I use the @PersistenceContext annotation to try to get a hold of that datasource and run the query. Problem I am having is:
javax.faces.el.EvaluationException: Cannot get value for expression '#{messageList.rowCount==0}
I assume because the query doesn't return anything. I'll post my config files and the code that executes the query. Am I on the right track with the configuration or just chasing my tail?
Thanks
Chris
persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
| <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="userDatabase">
| <provider>org.hibernate.ejb.HibernatePersistence</provider>
| <jta-data-source>java:/XAOracleDS</jta-data-source>
| <properties>
| <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle9Dialect" />
| <property name="hibernate.connection.driver_class" value="oracle.jdbc.driver.OracleDriver" />
| <property name="hibernate.connection.username" value="USER" />
| <property name="hibernate.connection.password" value="PASS" />
| <property name="hibernate.connection.datasource" value="java:/XAOracleDS"/>
| </properties>
| </persistence-unit>
| </persistence>
|
oracle-xa-ds.xml
<datasources>
| <xa-datasource>
| <jndi-name>XAOracleDS</jndi-name>
| <track-connection-by-tx>true</track-connection-by-tx>
| <isSameRM-override-value>false</isSameRM-override-value>
| <xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>
| <xa-datasource-property name="URL">
| jdbc:oracle:thin:@funeral:1521:DB
| </xa-datasource-property>
| <xa-datasource-property name="User">USER</xa-datasource-property>
| <xa-datasource-property name="Password">PASS</xa-datasource-property>
| <exception-sorter-class-name>
| org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter
| </exception-sorter-class-name>
| <no-tx-separate-pools/>
| </xa-datasource>
|
| <mbean code="org.jboss.resource.adapter.jdbc.vendor.OracleXAExceptionFormatter"
| name="jboss.jca:service=OracleXAExceptionFormatter">
| <depends optional-attribute-name="TransactionManagerService">
| jboss:service=TransactionManager
| </depends>
| </mbean>
| </datasources>
MessageManagerBean.java
//$Id: MessageManagerBean.java,v 1.7 2006/11/19 21:01:33 gavin Exp $
| package org.jboss.seam.example.messagesTest;
|
| import static javax.persistence.PersistenceContextType.EXTENDED;
| import static org.jboss.seam.ScopeType.SESSION;
|
| import java.io.Serializable;
| import java.util.List;
|
| import javax.ejb.Remove;
| import javax.ejb.Stateful;
| import javax.persistence.EntityManager;
| import javax.persistence.PersistenceContext;
|
| import org.jboss.seam.annotations.Destroy;
| import org.jboss.seam.annotations.Factory;
| import org.jboss.seam.annotations.Name;
| import org.jboss.seam.annotations.Out;
| import org.jboss.seam.annotations.In;
| import org.jboss.seam.annotations.Scope;
| import org.jboss.seam.annotations.datamodel.DataModel;
| import org.jboss.seam.annotations.datamodel.DataModelSelection;
|
| @Stateful
| @Scope(SESSION)
| @Name("messageManagerTest")
| public class MessageManagerBean implements Serializable, MessageManager
| {
|
| @DataModel
| private List<Message> messageList;
|
| @DataModelSelection
| @Out(required=false)
| private Message message;
|
| @PersistenceContext(type=EXTENDED)
| private EntityManager em;
|
| @Factory("messageList")
| public void findMessages()
| {
| messageList = em.createQuery("select unitid from iped_hd").getResultList();
| }
|
| @Remove @Destroy
| public void destroy() {}
|
| }
messages.jsp
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
| <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
| <%@ taglib uri="http://jboss.com/products/seam/taglib" prefix="s" %>
| <html>
| <head>
| <title>Messages</title>
| </head>
| <body>
| <f:view>
| <h2>Message List</h2>
| <h:outputText value="No messages to display" rendered="#{messageList.rowCount==0}"/>
| <h:dataTable var="msg" value="#{messageList}" rendered="#{messageList.rowCount>0}">
| <h:column>
| <f:facet name="header">
| <h:outputText value="Title"/>
| </f:facet>
| <h:outputText value="#{msg.unitid}"/>
| </h:column>
| </h:dataTable>
| </f:view>
| </body>
| </html>
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4009693#4009693
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4009693
More information about the jboss-user
mailing list