iBatis Error parsing XPath '/sqlMapConfig/sqlMap' - java

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.

Related

Hibernate: Unable to build entity manager factory (entity-mappings.xml)

I am using Hibernate JPA on a desktop application because generic SQL queries is almost impossible and I don't want to implement my own JPA.
I want to use non annotated entity classes because I'm using a library shared by the desktop app and an android app so I want to keep everything in XML. However Hibernate failed to build entity manager factory giving me the following error.
Caused by: org.hibernate.boot.MappingException: Unable to resolve explicitly named mapping-file : com/model/entity/TransferType.xml : origin(com/model/entity/TransferType.xml)
at org.hibernate.boot.model.process.internal.ScanningCoordinator.applyScanResultsToManagedResources(ScanningCoordinator.java:213)
at org.hibernate.boot.model.process.internal.ScanningCoordinator.coordinateScan(ScanningCoordinator.java:81)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.prepare(MetadataBuildingProcess.java:98)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:194)
at org.hibernate.jpa.boot.spi.Bootstrap.getEntityManagerFactoryBuilder(Bootstrap.java:34)
at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilder(HibernatePersistenceProvider.java:165)
at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:114)
at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:71)
at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:52)
Here is the mapping file xml I used
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
version="2.0">
<entity class="app.model.DeviceType">
<table name="DEVICE_TYPE"
schema="my_schema"
catalog=""/>
<attributes>
<id name="type">
<column name="type"/>
</id>
</attributes>
</entity>
</entity-mappings>
How do I fixe this? What I am doing wrong in here?

Invalid column name with Hibernate NamedQuery

My Hibernate hbm file looks like this. I had issues when running this query. The query was running fine on sql developer, but when running through my java application, it is throwing SQL Error: 17006, SQLState: 99999 error which is saying Invalid Column. I tried many ways to take columns off and change property names but could not find a solution.
2015-07-16 12:15:14,374 [http-bio-8080-exec-8] DEBUG com.adp.au.hibernate.HibernateUtils - HibernateUtils.closeSession(false) for session depth: [1]
2015-07-16 12:15:14,389 [http-bio-8080-exec-8] ERROR com.adp.au.timesheet.action.SubmitError - Client: [29010], User: [ADMIN] exception: [could not execute query]
2015-07-16 12:15:14,389 [http-bio-8080-exec-8] ERROR com.adp.au.timesheet.action.SubmitError - Client: [29010], User: [ADMIN] stacktrace: org.hibernate.exception.GenericJDBCException: could not execute query
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:140)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:128)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.loader.Loader.doList(Loader.java:2545)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)
at org.hibernate.loader.Loader.list(Loader.java:2271)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:316)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1842)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:165)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:157)
at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:890)
Could someone please look into this and help me?
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class mutable="false" name="com.adp.au.timesheet.external.PLClient">
<id name="clientId"/>
<property name="branch"/>
<property name="name"/>
<property name="timesheetType"/>
<property name="costSplitting" type="yes_no"/>
<property name="payconReportCode"/>
<property name="ownEftUseInd" type="yes_no"/>
<property name="essUse" type="integer"/>
</class>
<sql-query name="plClient.byClientId.forABAFile" read-only="true">
<return alias="client" class="com.adp.au.timesheet.external.PLClient"/>
SELECT
TRIM(CLI_ID) AS {client.clientId},
OWN_EFT_USE_IND AS {client.ownEftUseInd}
FROM SAG.PL_CLI`
WHERE (TRIM(PL_CLI.CEASED_DATE) IS NULL OR PL_CLI.CEASED_DATE >TO_CHAR(SYSDATE, 'YYYYMMDD'))
AND PL_CLI.CLI_ID = RPAD(:clientId, 7)
</sql-query>
</hibernate-mapping>

configure hibernate configuration file

following is my hibernate.cfg.xml file
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/hibernate</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect </property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property>
<!-- Names the annotated entity class -->
<mapping class="org.javabrains.koushik.dto.UserDetails"/>
</session-factory>
</hibernate-configuration>
Error I am getting is as follows
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml
Stack Trace:
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2246)
at org.hibernate.cfg.Configuration.configure(Configuration.java:2158)
at org.hibernate.cfg.Configuration.configure(Configuration.java:2137)
at org.koushik.hibernate.HibernateTest.main(HibernateTest.java:13)
Caused by: org.dom4j.DocumentException: Error on line 1 of document : The processing instruction target matching "[xX][mM][lL]" is not allowed. Nested exception: The processing instruction target matching "[xX][mM][lL]" is not allowed.
at org.dom4j.io.SAXReader.read(SAXReader.java:482)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2238)
... 3 more
I am new to Hibernate. Was following a tutorial. Got this error. Can anybody help me with this??
you need to add:
<?xml version="1.0" encoding="utf-8"?>
at the beginning of your xml file.
Edit:(after you updated your code)
check if there are some blank space or other content before the <?xml ?>
check if there is a Byte Order Mark (BOM) before the <?xml ?> (here is a tutorial to remove it)
check if there is another <?xml ?> definition in your document
if any one get this The processing instruction target matching "[xX][mM][lL]" is not allowed. error
Solution to this error is that
1.This line should be the firs line and should not leave any space before this line.

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

Retreieve CLOB data using Ibatis 2.3

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

Categories

Resources