Retreieve CLOB data using Ibatis 2.3 - java

I am trying to retrieve a clob data from the oracle database as shown in reports.xml.i am using oracle jdbc driver version "Oracle JDBC Driver version - 10.0.2.0.0" . The following are the errors i receive ,kindly let me know ,how to resolve this.
2011-08-31 13:03:40,790 WARN [org.apache.struts.chain.commands.AbstractExceptionHandler] (http-10.12.230.222-8080-1) Unhandled exception
com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred in sa/mobily/telecop/dao/config/GenericReportQuery.xml.
--- The error occurred while applying a parameter map.
--- Check the runReportQuery-InlineParameterMap.
--- Check the parameter mapping for the 'QUERY' property.
--- Cause: java.sql.SQLException: Data size bigger than max size for this type: 6411
at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryWithCallback(MappedStatement.java:201)
at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryForList(MappedStatement.java:139)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:567)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:541)
at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForList(SqlMapSessionImpl.java:118)
at com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForList(SqlMapClientImpl.java:94)
reports.xml
<select id="getReportQuery" parameterClass="java.util.HashMap" resultMap="queryStringData" >
select REPORT_QUERY
from frd_rep_fw_reports where report_id=#REP_ID# AND report_type='P'
</select>
<resultMap id="queryStringData" class="java.util.HashMap">
<result column="REPORT_QUERY" property="QRY_BODY" javaType="java.lang.String" jdbcType="CLOB" typeHandler="com.ibatis.sqlmap.engine.type.ClobTypeHandlerCallback" />
</resultMap>
sqlmapconfig.xml
<dataSource type="JNDI">
<property name="DataSource" value="${connection.datasource}"/>
<property name="Driver.SetBigStringTryClob" value="true"/>
</dataSource>

Get the latest ojdbc14.jar and i should work. Also let me know how the table frd_rep_fw_reports is defined

Related

H2 Database with Hibernate error Caused by: org.h2.jdbc.JdbcSQLIntegrityConstraintViolationException: Unique index or primary key

I am getting JdbcSQLIntegrityConstraintViolationException exception while starting my server.
Seems like some problem in using <map>, earlier it was working file with older version of H2 but now not working.
My curren H2 version is:
implementation group: 'com.h2database', name: 'h2', version: '1.4.200'
Older was:
compile group: 'com.h2database', name: 'h2', version: '1.4.193'
My class is using simple map variable like: private Map<String, String> extraData;
Can someone tell me, how to fix this???
Thanks
Here is my XML snippet:
<class name="pojo.MachineInstruction" >
<id name="machineId" type="java.lang.Integer"/>
<!--Time stamp is auto generated. No need to set the value..-->
<timestamp name="timestamp"/>
<property name="instructionType" not-null="true">
<type name="org.hibernate.type.EnumType">
<param name="enumClass">pojo.MachineInstructionType</param>
</type>
</property>
<property name="instructionStatus" not-null="true">
<type name="org.hibernate.type.EnumType">
<param name="enumClass">pojo.MachineInstructionStatus</param>
</type>
</property>
<property name="version" type="java.lang.String"/>
<map name="extraData" cascade="all">
<key column="extraData" />
<map-key type="text" column="key"/>
<element type="text" column="value"/>
</map>
</class>
Caused by: org.h2.jdbc.JdbcSQLIntegrityConstraintViolationException: Unique index or primary key violation: "PRIMARY KEY ON """".PAGE_INDEX"; SQL statement:
ALTER TABLE PUBLIC.MACHINEINSTRUCTION_EXTRADATA ADD CONSTRAINT PUBLIC.FKROHO504EJPG9G4R81YYKTV44K FOREIGN KEY(EXTRADATA) REFERENCES PUBLIC.MACHINEINSTRUCTION(MACHINEID) NOCHECK [23505-200]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:459)
at org.h2.message.DbException.getJdbcSQLException(DbException.java:429)
at org.h2.message.DbException.get(DbException.java:205)
at org.h2.message.DbException.get(DbException.java:181)
at org.h2.pagestore.db.PageDataIndex.add(PageDataIndex.java:125)
at org.h2.pagestore.PageStore.addMeta(PageStore.java:1804)
at org.h2.pagestore.db.PageBtreeIndex.<init>(PageBtreeIndex.java:65)
at org.h2.pagestore.db.PageStoreTable.addIndex(PageStoreTable.java:183)
at org.h2.command.ddl.AlterTableAddConstraint.createIndex(AlterTableAddConstraint.java:298)
at org.h2.command.ddl.AlterTableAddConstraint.tryUpdate(AlterTableAddConstraint.java:223)
at org.h2.command.ddl.AlterTableAddConstraint.update(AlterTableAddConstraint.java:78)
at org.h2.engine.MetaRecord.execute(MetaRecord.java:60)
at org.h2.engine.Database.open(Database.java:759)
at org.h2.engine.Database.openDatabase(Database.java:307)
at org.h2.engine.Database.<init>(Database.java:301)
at org.h2.engine.Engine.openSession(Engine.java:74)
at org.h2.engine.Engine.openSession(Engine.java:192)
at org.h2.engine.Engine.createSessionAndValidate(Engine.java:171)
at org.h2.engine.Engine.createSession(Engine.java:166)
at org.h2.engine.Engine.createSession(Engine.java:29)
at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:340)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:173)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:152)
at org.h2.Driver.connect(Driver.java:69)
at org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator.makeConnection(DriverConnectionCreator.java:38)
... 35 more
Unfortunately, H2 1.4.* and older versions don't have automatic upgrade procedure, it is under responsibility of their users.
https://h2database.com/html/tutorial.html#upgrade_backup_restore
(The upcoming H2 2.0 will have a built-in upgrade utility and will refuse to open old files without upgrade to avoid such issues.)
1.4.196 and older versions had a bug with some combinations of indexes and referential constraints, it was fixed in 1.4.197, but upgrade path for the legacy PageStore engine wasn't provided. MVStore also had similar upgrade issues, but they were fixed.
Right now your database seems to be corrupted, because upgrade wasn't performed. You need to write some dummy implementation of org.h2.api.DatabaseEventListener, put it into the classpath of your application (classpath of your server if you use separate H2 Server process), and open your database with ;DATABASE_EVENT_LISTENER='path.to.YourListener' appended to JDBC connection URL. Wrong constraints will be logged to your listener. After that you will be able to export your database to the SQL Script with SCRIPT TO 'filename.sql' command and create a new database file and populate it with that script with RUNSCRIPT FROM 'filename.sql'.

How to connect to Oracle 12c PDB using Hibernate

I have created a sample Oracle 12c PDB (Pluggable Data Base) using the instructions from here. How do I connect to this pluggable database using Hibernate application? I am using a sample Hibernate application from here
I changed the hibernate.cfg.xml file as follows:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.url">jdbc:oracle:thin:#localhost:1521:sys</property>
<property name="connection.username">sys as sysdba</property>
<property name="connection.password">helloWORLD12</property>
<property name="connection.driver_class">oracle.jdbc.OracleDriver</property>
<property name="dialect">org.hibernate.dialect.Oracle12cDialect</property>
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="hbm2ddl.auto">create</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<property name="current_session_context_class">thread</property>
<mapping class="net.codejava.hibernate.Book" />
</session-factory>
</hibernate-configuration>
But I am getting the following error trace when I run the program:
Exception in thread "main" org.hibernate.HibernateException: Error accessing stax stream
at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:107)
at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:65)
at org.hibernate.boot.cfgxml.internal.ConfigLoader.loadConfigXmlResource(ConfigLoader.java:57)
at org.hibernate.boot.registry.StandardServiceRegistryBuilder.configure(StandardServiceRegistryBuilder.java:163)
at net.codejava.hibernate.BookManager.setup(BookManager.java:23)
at net.codejava.hibernate.BookManager.main(BookManager.java:100)
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[18,6]
Message: The processing instruction target matching "[xX][mM][lL]" is not allowed.
at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:604)
at com.sun.xml.internal.stream.XMLEventReaderImpl.peek(XMLEventReaderImpl.java:276)
at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:103)
... 5 more
Kindly let me know where I am going wrong. There are almost no resources online for using Oracle 12c PDB with Hibernate.
UPDATE 1: I had an extra line of XML code in my config file which lead to the XML parsing error. Now - how do I associate a CDB/PDB with a particular user account, since using the PDB through SYS user is not recommended.
I have a PDB named 'pdb1', and it is associated with sys user account. It is stored at the following location:
D:\app\myusername\virtual\oradata\orcl\pdb1
I created a new user 'c##test' and then created a pdb while logged in to the user 'c##test' using the following command:
create pluggable database pdb3 admin user pdb_admin3 identified by helloWORLD12
file_name_convert=('D:\app\myusername\virtual\oradata\orcl\pdbseed\',
'D:\app\myusername\virtual\oradata\test\pdb3\');
'pdb3' is created successfully, but it is not getting associated to the user 'c##test'.
The error trace I am getting now is as follows: https://pastebin.com/skVMLkqT
The issue is with the syntax you are using. you are using :SID instead of /SERVICE_NAME , so make sure to change this line as :
<property name="connection.url">jdbc:oracle:thin:#localhost:1521/sys</property>
to see which services available, execute lsnrctl service.
Please also note that you are trying to use sys account which is a the
same as root. to avoid future problems, it's best practice to create a
new account an use that instead.
according to your stack trace you missed oracle driver dependency:
ClassNotFoundException: Could not load requested class :
oracle.jdbc.OracleDriver
you should add this dependecy to your pom.xml file,Please take these steps for that:
1- Download ojdbc8.jar from oracle site:
https://www.oracle.com/technetwork/database/features/jdbc/jdbc-ucp-122-3110062.html
2- Install ojdbc8 to your local maven repository:
specify you path instead of Path/to/your/
mvn install:install-file -Dfile={Path/to/your/ojdbc8.jar} DgroupId=com.oracle -DartifactId=ojdbc8 -Dversion=12.2.0.1 -Dpackaging=jar
3-Add Dependency to Pom.xml
<!-- ORACLE database driver -->
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc8</artifactId>
<version>12.2.0.1</version>
</dependency>

iBatis Error parsing XPath '/sqlMapConfig/sqlMap'

i'm new to ibatis. i like to split the SQLMapConfig file and SQL map resources into 2 file. but when i run the project its seems to show an error.
so below are my 2 file SQL Map.
SQLMapConfig.xml :
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMapConfig PUBLIC "-//iBATIS.com//DTD SQL Map Config
2.0//EN" "http://www.ibatis.com/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
<settings
cacheModelsEnabled="true"
enhancementEnabled="true"
lazyLoadingEnabled="true"
maxRequests="32"
maxSessions="10"
maxTransactions="5"
useStatementNamespaces="false"
/>
<transactionManager type="JDBC" >
<dataSource type="DBCP">
<property name="JDBC.Driver" value="com.mysql.jdbc.Driver"/>
<property name="JDBC.ConnectionURL" value="jdbc:mysql://localhost:3306/sms_converter"/>
<property name="JDBC.Username" value="root"/>
<property name="JDBC.Password" value=""/>
</dataSource>
</transactionManager>
<sqlMap resource="configuration/db/tbluser.xml" />
</sqlMapConfig>
and here is the SQL Map resources tbluser.xml :
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN" "http://www.ibatis.com/dtd/sql-map-2.dtd">
<sqlMap namespace="MUser">
<select id="getUserById" parameterClass = "com.me.bean.MUser" resultClass="com.me.bean.MUser">
SELECT user_id AS sUserId FROM users where user.id = #sUserId#
</select>
</sqlMap>
but after i run the project i've got this error :
Exception in thread "main" java.lang.RuntimeException: Error occurred. Cause: com.ibatis.common.xml.NodeletException: Error parsing XML. Cause: java.lang.RuntimeException: Error parsing XPath '/sqlMapConfig/sqlMap'. Cause: java.io.IOException: Could not find resource configuration/db/tbluser.xml
at com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser.parse(SqlMapConfigParser.java:49)
at com.ibatis.sqlmap.client.SqlMapClientBuilder.buildSqlMapClient(SqlMapClientBuilder.java:63)
at com.me.dao.DBDao.main(DBDao.java:77)
Caused by: com.ibatis.common.xml.NodeletException: Error parsing XML. Cause: java.lang.RuntimeException: Error parsing XPath '/sqlMapConfig/sqlMap'. Cause: java.io.IOException: Could not find resource configuration/db/tbluser.xml
at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:53)
at com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser.parse(SqlMapConfigParser.java:46)
... 2 more
Caused by: java.lang.RuntimeException: Error parsing XPath '/sqlMapConfig/sqlMap'. Cause: java.io.IOException: Could not find resource configuration/db/tbluser.xml
at com.ibatis.common.xml.NodeletParser.processNodelet(NodeletParser.java:123)
at com.ibatis.common.xml.NodeletParser.process(NodeletParser.java:84)
at com.ibatis.common.xml.NodeletParser.process(NodeletParser.java:102)
at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:72)
at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:51)
... 3 more
Caused by: java.io.IOException: Could not find resource configuration/db/tbluser.xml
at com.ibatis.common.resources.Resources.getResourceAsStream(Resources.java:110)
at com.ibatis.common.resources.Resources.getResourceAsStream(Resources.java:95)
at com.ibatis.common.resources.Resources.getResourceAsReader(Resources.java:161)
at com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser$10.process(SqlMapConfigParser.java:262)
at com.ibatis.common.xml.NodeletParser.processNodelet(NodeletParser.java:121)
... 7 more
can anyone help me? thanks.
Could not find resource configuration/db/tbluser.xml, so try add prefix classpath:
<mapper resource="classpath:configuration/db/tbluster.xml">
try use
<typeAlias alias="classMUser" type="com.me.bean.MUser" />
<resultMap id="userMap" class="classMUser">
<result property="sUserId" column="sUserId" />
</resultMap>
<select id="getUserById" parameterClass = "com.me.bean.MUser" resultMap="userMap">
SELECT user_id AS sUserId FROM users where user.id = #sUserId#
</select>
In my case, the issue was:
<select id="someId" parameterClass="hashmap"
resultClass="someResultClass" resultMap="someResultMap">
I have written "hashmap" in resultMap instead of "someResultMap".
Correcting this solved the compilation issue.

Spring Integration - Message Store configuration for Microsoft SQL Server 2012

I setup a MessageStore in Spring Integration using JDBC, following there's my configuration:
<bean id="queryProvider" class="org.springframework.integration.jdbc.store.channel.MySqlChannelMessageStoreQueryProvider" />
<!-- JDBC message store configuration -->
<bean id="store" class="org.springframework.integration.jdbc.store.JdbcChannelMessageStore">
<property name="dataSource" ref="basicDataSource" />
<property name="channelMessageStoreQueryProvider" ref="queryProvider" />
<property name="region" value="TX_TIMEOUT" />
<property name="usingIdCache" value="true" />
</bean>
My underlying DB is Microsoft SQL Server 2012 and when starting up the server I get the following exception:
nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near 'LIMIT'.
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:83)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:605)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:639)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:664)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:704)
How can I fix this problem?
The best way to implement SqlServerChannelMessageStoreQueryProvider and don't use MySqlChannelMessageStoreQueryProvider, because those RDBMS vendors use different DML.
Feel free to raise a JIRA ticket and even contribute!

org.jumpmind.db.model.ModelException: Unknown JDBC type DATETIME

I am using this XML document to load a specific table into a postgresql database:
create_table.xml:
<?xml version="1.0"?>
<!DOCTYPE database SYSTEM "http://db.apache.org/torque/dtd/database.dtd">
<database name="sample">
<table name="Location">
<column name="LocationID" type="INTEGER" primaryKey="true" />
<column name="LocationModifyDate" type="DATETIME" required="true" />
</table>
</database>
But when I load it, I get an exception:
An exception occurred. Please see the following for details:
-------------------------------------------------------------------------------
org.jumpmind.db.model.ModelException: Unknown JDBC type DATETIME
at org.jumpmind.db.model.Column.setMappedType(Column.java:283)
at org.jumpmind.db.io.DatabaseXmlUtil.nextTable(DatabaseXmlUtil.java:202)
at org.jumpmind.symmetric.io.data.reader.XmlDataReader.readNext(XmlDataReader.java:139)
at org.jumpmind.symmetric.io.data.reader.XmlDataReader.open(XmlDataReader.java:75)
at org.jumpmind.symmetric.io.data.DataProcessor.process(DataProcessor.java:84)
at org.jumpmind.symmetric.io.data.DataProcessor.process(DataProcessor.java:78)
at org.jumpmind.symmetric.io.data.DbImport.importTablesFromXml(DbImport.java:208)
at org.jumpmind.symmetric.io.data.DbImport.importTables(DbImport.java:154)
at org.jumpmind.symmetric.DbImportCommand.executeWithOptions(DbImportCommand.java:188)
at org.jumpmind.symmetric.AbstractCommandLauncher.execute(AbstractCommandLauncher.java:130)
at org.jumpmind.symmetric.DbImportCommand.main(DbImportCommand.java:72)
The command I use to load the XML file is this:
../bin/dbimport --engine corp-000 -format XML create_table.xml
If I use INTEGER rather than DATETIME, the XML file is processed correctly and the table is created.
What does this exception mean? Maybe I have to use a JDBC Standard datatype?
Use timestamp instead of DATETIME
<column name="LocationModifyDate" type="TIMESTAMP" required="true" />
Read the manual for date/time in postgresql here:
http://www.postgresql.org/docs/9.1/static/datatype-datetime.html

Categories

Resources