JBoss Community

Oracle User Type Mappings

reply from Bob Frapples in Datasource Configuration - View the full discussion

Here is the relevant code:

 

From myDS-ds.xml

 

{code:xml}

<datasources>
  <local-tx-datasource>
    <jndi-name>jdbc/MyDS</jndi-name>
    <use-java-context>false</use-java-context>
    <connection-url>jdbc:oracle:thin:@1.1.1.1:1521:orcl</connection-url>
    <driver-class>oracle.jdbc.OracleDriver</driver-class>
    <user-name>user</user-name>
    <password>pass</password>
    <!-- Uses the pingDatabase method to check a connection is still valid before handing it out from the pool -->
    <!--valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleValidConnectionChecker</valid-connection-checker-class-name-->
    <!-- Checks the Oracle error codes and messages for fatal errors -->
    <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
        <!-- sql to call when connection is created
        <new-connection-sql>some arbitrary sql</new-connection-sql>
        -->

        <!-- sql to call on an existing pooled connection when it is obtained from pool - the OracleValidConnectionChecker is prefered -->
    <check-valid-connection-sql>SELECT * FROM DUAL</check-valid-connection-sql>

    <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
    <metadata>
       <type-mapping>Oracle9i</type-mapping>
    </metadata>
  </local-tx-datasource>

</datasources>

{code}

 

From application-context.xml

 

{code:xml}

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">

  <property name="jndiName" value="jdbc/MyDS" /> 

  <property name="expectedType" value="javax.sql.DataSource"/>

</bean>

{code}

 

From AppContext.java

 

{code}

((DataSource)ctx.getBean("dataSource")).getConnection.setTypeMap(MyMappings.TYPE_MAP);

{code}

 

 

 

 

 

 

 

 

From MyMappings.java

 

{code}

public

 

 

static final Map<String, Class<?>> TYPE_MAP = new

HashMap<String, Class<?>>();

 

 

static

{

 

 

 

TYPE_MAP

 

 

.put(User.SQLTypeName, User.class

);

 

{code}

 

Here is the stack trace:

 

{code}

2010-07-20 08:29:52,715 ERROR [STDERR] (http-127.0.0.1-8080-1) java.lang.ClassCastException: oracle.sql.STRUCT cannot be cast to editor.hibernate.model.User
2010-07-20 08:29:52,715 ERROR [STDERR] (http-127.0.0.1-8080-1)  at editor.hibernate.dao.function.FnGetUserByName.execute(FnGetUserByName.java:33)
2010-07-20 08:29:52,730 ERROR [STDERR] (http-127.0.0.1-8080-1)  at editor.service.UserService.getUser(UserService.java:55)
2010-07-20 08:29:52,730 ERROR [STDERR] (http-127.0.0.1-8080-1)  at editor.service.UserService.userLogin(UserService.java:66)
2010-07-20 08:29:52,730 ERROR [STDERR] (http-127.0.0.1-8080-1)  at editor.controller.LoginController.login(LoginController.java:42)
2010-07-20 08:29:52,730 ERROR [STDERR] (http-127.0.0.1-8080-1)  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2010-07-20 08:29:52,730 ERROR [STDERR] (http-127.0.0.1-8080-1)  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
2010-07-20 08:29:52,730 ERROR [STDERR] (http-127.0.0.1-8080-1)  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
2010-07-20 08:29:52,730 ERROR [STDERR] (http-127.0.0.1-8080-1)  at java.lang.reflect.Method.invoke(Method.java:597)
2010-07-20 08:29:52,730 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.springframework.web.servlet.mvc.multiaction.MultiActionController.invokeNamedMethod(MultiActionController.java:471)
2010-07-20 08:29:52,730 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.springframework.web.servlet.mvc.multiaction.MultiActionController.handleRequestInternal(MultiActionController.java:408)
2010-07-20 08:29:52,730 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
2010-07-20 08:29:52,730 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
2010-07-20 08:29:52,730 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)
2010-07-20 08:29:52,730 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
2010-07-20 08:29:52,730 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
2010-07-20 08:29:52,730 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:563)
2010-07-20 08:29:52,730 ERROR [STDERR] (http-127.0.0.1-8080-1)  at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
2010-07-20 08:29:52,730 ERROR [STDERR] (http-127.0.0.1-8080-1)  at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
2010-07-20 08:29:52,730 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
2010-07-20 08:29:52,730 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
2010-07-20 08:29:52,730 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
2010-07-20 08:29:52,730 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
2010-07-20 08:29:52,730 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
2010-07-20 08:29:52,730 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
2010-07-20 08:29:52,730 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
2010-07-20 08:29:52,730 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
2010-07-20 08:29:52,730 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
2010-07-20 08:29:52,730 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
2010-07-20 08:29:52,730 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
2010-07-20 08:29:52,730 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
2010-07-20 08:29:52,730 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
2010-07-20 08:29:52,730 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
2010-07-20 08:29:52,730 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
2010-07-20 08:29:52,730 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
2010-07-20 08:29:52,730 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
2010-07-20 08:29:52,730 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
2010-07-20 08:29:52,730 ERROR [STDERR] (http-127.0.0.1-8080-1)  at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
2010-07-20 08:29:52,730 ERROR [STDERR] (http-127.0.0.1-8080-1)  at java.lang.Thread.run(Thread.java:619)

{code}

 

 

Sorry for the bad formatting, I'm not used to this forum interface.  Hope it helps.

 

Thanks.

Reply to this message by going to Community

Start a new discussion in Datasource Configuration at Community