|
Hello,
I've got a table that maps to itself. I tried to construct correct mapping file but I was unsuccessful and ended up with exception ### Cause: java.sql.SQLException: ORA-00900: invalid SQL statement ; bad SQL grammar []; nested exception is java.sql.SQLException: ORA-00900: invalid SQL statement Is there any possibility to do such a mapping? My files: <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http:// mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="package_name.mappers.PeriodMapper"> <resultMap id="periodResultMap" type="package_name.Period"> <id property="id" column="id_period"/> <result property="periodname" column="name"/> <result property="kod" column="code"/> <result property="begdate" column="begdate"/> <result property="enddate" column="enddate"/> <result property="flag" column="flag"/> <association property="parent" column="par_id_period" resultMap="periodResuiltMap" select="selectPeriod"/> </resultMap> <select id="selectPeriod" parameterType="Long" resultMap="periodResultMap"> SELECT * FROM period WHERE id_period = #{id} </select> </mapper> CREATE TABLE period (id_period NUMBER NOT NULL, periodname VARCHAR2(255), kod VARCHAR2(8), par_id_period NUMBER, begdate DATE, enddate DATE, flag VARCHAR2(2)) and bean: public class Period { private Long id; private String name; private String code; private Period parent; private Date begDate; private Date endDate; public enum Flag { Y, Q, M } private Flag flag; get... set... } Thanks, Andrew |
|
From the exception you've posted, I don't think the problem is in your
mapping, are you sure #{id} is being correctly set. Try to get MyBatis to log some output so you can see if it is being correctly set. Also in your PeriodMapper.java try selectPeriod(@Param("id") Long id) After you have sorted that out make sure that the asterisk (*) in your select statement is actually returning the correct column names. IMHO it is best to stay away from * - be specific about which columns you want. Regards Jorge On Dec 22, 9:31 pm, demosfen <[hidden email]> wrote: > Hello, > > I've got a table that maps to itself. I tried to construct correct > mapping file but I was unsuccessful and ended up with exception > ### Cause: java.sql.SQLException: ORA-00900: invalid SQL statement > ; bad SQL grammar []; nested exception is java.sql.SQLException: > ORA-00900: invalid SQL statement > > Is there any possibility to do such a mapping? > > My files: > > <?xml version="1.0" encoding="UTF-8" ?> > <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http:// > mybatis.org/dtd/mybatis-3-mapper.dtd"> > <mapper namespace="package_name.mappers.PeriodMapper"> > <resultMap id="periodResultMap" type="package_name.Period"> > <id property="id" column="id_period"/> > <result property="periodname" column="name"/> > <result property="kod" column="code"/> > <result property="begdate" column="begdate"/> > <result property="enddate" column="enddate"/> > <result property="flag" column="flag"/> > <association property="parent" column="par_id_period" > resultMap="periodResuiltMap" select="selectPeriod"/> > </resultMap> > <select id="selectPeriod" parameterType="Long" > resultMap="periodResultMap"> > SELECT * FROM period WHERE id_period = #{id} > </select> > </mapper> > > CREATE TABLE period > (id_period NUMBER NOT NULL, > periodname VARCHAR2(255), > kod VARCHAR2(8), > par_id_period NUMBER, > begdate DATE, > enddate DATE, > flag VARCHAR2(2)) > and bean: > > public class Period { > private Long id; > private String name; > private String code; > private Period parent; > private Date begDate; > private Date endDate; > public enum Flag { > Y, Q, M > } > private Flag flag; > get... set... > > } > > Thanks, > Andrew |
|
<select id="selectPeriod" parameterType="Long"
resultMap="periodResultMap"> SELECT * FROM period WHERE id_period = #{id} </select> this have some problem 2011/12/23 Bokie <[hidden email]> From the exception you've posted, I don't think the problem is in your |
|
I fixed problem with "bad SQL grammar" exception, the problem was
incorrect annotation in PeriodMapper interface. Data loading started in some way ... but failed with: java.lang.OutOfMemoryError: Java heap space java.util.Arrays.copyOfRange(Arrays.java:3209) java.lang.String.<init>(String.java:215) java.lang.StringBuilder.toString(StringBuilder.java:430) java.lang.Throwable.toString(Throwable.java:344) java.lang.String.valueOf(String.java:2826) java.lang.StringBuilder.append(StringBuilder.java:115) org.apache.ibatis.executor.resultset.NestedResultSetHandler.applyNestedResultMappings(NestedResultSetHandler.java: 152) org.apache.ibatis.executor.resultset.NestedResultSetHandler.getRowValue(NestedResultSetHandler.java: 98) org.apache.ibatis.executor.resultset.NestedResultSetHandler.applyNestedResultMappings(NestedResultSetHandler.java: 127) org.apache.ibatis.executor.resultset.NestedResultSetHandler.getRowValue(NestedResultSetHandler.java: 98) org.apache.ibatis.executor.resultset.NestedResultSetHandler.applyNestedResultMappings(NestedResultSetHandler.java: 127) ... It looks like MyBatis can't handle recursive mapping. Can anyone clear this up? Is it possible to write recursive mapping statements at all? Thanks, Andrew On 24 дек, 03:08, c c <[hidden email]> wrote: > <select id="selectPeriod" parameterType="Long" > resultMap="periodResultMap"> > SELECT * FROM period WHERE id_period = #{id} > </select> > > this have some problem > > 2011/12/23 Bokie <[hidden email]> > > > > > > > > > From the exception you've posted, I don't think the problem is in your > > mapping, are you sure #{id} is being correctly set. > > Try to get MyBatis to log some output so you can see if it is being > > correctly set. Also in your PeriodMapper.java try > > selectPeriod(@Param("id") Long id) > > > After you have sorted that out make sure that the asterisk (*) in your > > select statement is actually returning the correct column names. > > IMHO it is best to stay away from * - be specific about which columns > > you want. > > > Regards > > Jorge > > > On Dec 22, 9:31 pm, demosfen <[hidden email]> wrote: > > > Hello, > > > > I've got a table that maps to itself. I tried to construct correct > > > mapping file but I was unsuccessful and ended up with exception > > > ### Cause: java.sql.SQLException: ORA-00900: invalid SQL statement > > > ; bad SQL grammar []; nested exception is java.sql.SQLException: > > > ORA-00900: invalid SQL statement > > > > Is there any possibility to do such a mapping? > > > > My files: > > > > <?xml version="1.0" encoding="UTF-8" ?> > > > <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http:// > > > mybatis.org/dtd/mybatis-3-mapper.dtd"> > > > <mapper namespace="package_name.mappers.PeriodMapper"> > > > <resultMap id="periodResultMap" type="package_name.Period"> > > > <id property="id" column="id_period"/> > > > <result property="periodname" column="name"/> > > > <result property="kod" column="code"/> > > > <result property="begdate" column="begdate"/> > > > <result property="enddate" column="enddate"/> > > > <result property="flag" column="flag"/> > > > <association property="parent" column="par_id_period" > > > resultMap="periodResuiltMap" select="selectPeriod"/> > > > </resultMap> > > > <select id="selectPeriod" parameterType="Long" > > > resultMap="periodResultMap"> > > > SELECT * FROM period WHERE id_period = #{id} > > > </select> > > > </mapper> > > > > CREATE TABLE period > > > (id_period NUMBER NOT NULL, > > > periodname VARCHAR2(255), > > > kod VARCHAR2(8), > > > par_id_period NUMBER, > > > begdate DATE, > > > enddate DATE, > > > flag VARCHAR2(2)) > > > and bean: > > > > public class Period { > > > private Long id; > > > private String name; > > > private String code; > > > private Period parent; > > > private Date begDate; > > > private Date endDate; > > > public enum Flag { > > > Y, Q, M > > > } > > > private Flag flag; > > > get... set... > > > > } > > > > Thanks, > > > Andrew |
|
In reply to this post by demosfen
For this to work you need to remove the "resultMap" attribute from the
"association" element like this: <resultMap id="periodResultMap" type="Period"> <id property="id" column="id_period"/> <result property="periodname" column="name"/> <result property="kod" column="code"/> <result property="begdate" column="begdate"/> <result property="enddate" column="enddate"/> <result property="flag" column="flag"/> <association property="parent" column="par_id_period" select="selectPeriod"/> </resultMap> <select id="selectPeriod" parameterType="Long" resultMap="periodResultMap"> SELECT * FROM period WHERE id_period = #{id} </select> On Dec 22, 9:31 pm, demosfen <[hidden email]> wrote: > Hello, > > I've got a table that maps to itself. I tried to construct correct > mapping file but I was unsuccessful and ended up with exception > ### Cause: java.sql.SQLException: ORA-00900: invalid SQL statement > ; bad SQL grammar []; nested exception is java.sql.SQLException: > ORA-00900: invalid SQL statement > > Is there any possibility to do such a mapping? > > My files: > > <?xml version="1.0" encoding="UTF-8" ?> > <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http:// > mybatis.org/dtd/mybatis-3-mapper.dtd"> > <mapper namespace="package_name.mappers.PeriodMapper"> > <resultMap id="periodResultMap" type="package_name.Period"> > <id property="id" column="id_period"/> > <result property="periodname" column="name"/> > <result property="kod" column="code"/> > <result property="begdate" column="begdate"/> > <result property="enddate" column="enddate"/> > <result property="flag" column="flag"/> > <association property="parent" column="par_id_period" > resultMap="periodResuiltMap" select="selectPeriod"/> > </resultMap> > <select id="selectPeriod" parameterType="Long" > resultMap="periodResultMap"> > SELECT * FROM period WHERE id_period = #{id} > </select> > </mapper> > > CREATE TABLE period > (id_period NUMBER NOT NULL, > periodname VARCHAR2(255), > kod VARCHAR2(8), > par_id_period NUMBER, > begdate DATE, > enddate DATE, > flag VARCHAR2(2)) > and bean: > > public class Period { > private Long id; > private String name; > private String code; > private Period parent; > private Date begDate; > private Date endDate; > public enum Flag { > Y, Q, M > } > private Flag flag; > get... set... > > } > > Thanks, > Andrew |
|
Thank you, Bokie. I changed my example and it works now.
On 25 дек, 02:27, Bokie <[hidden email]> wrote: > For this to work you need to remove the "resultMap" attribute from the > "association" element like this: > > <resultMap id="periodResultMap" type="Period"> > <id property="id" column="id_period"/> > <result property="periodname" column="name"/> > <result property="kod" column="code"/> > <result property="begdate" column="begdate"/> > <result property="enddate" column="enddate"/> > <result property="flag" column="flag"/> > <association property="parent" column="par_id_period" > select="selectPeriod"/> > </resultMap> > <select id="selectPeriod" parameterType="Long" > resultMap="periodResultMap"> > SELECT * > FROM period > WHERE id_period = #{id} > </select> > > On Dec 22, 9:31 pm, demosfen <[hidden email]> wrote: > > > > > > > > > Hello, > > > I've got a table that maps to itself. I tried to construct correct > > mapping file but I was unsuccessful and ended up with exception > > ### Cause: java.sql.SQLException: ORA-00900: invalid SQL statement > > ; bad SQL grammar []; nested exception is java.sql.SQLException: > > ORA-00900: invalid SQL statement > > > Is there any possibility to do such a mapping? > > > My files: > > > <?xml version="1.0" encoding="UTF-8" ?> > > <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http:// > > mybatis.org/dtd/mybatis-3-mapper.dtd"> > > <mapper namespace="package_name.mappers.PeriodMapper"> > > <resultMap id="periodResultMap" type="package_name.Period"> > > <id property="id" column="id_period"/> > > <result property="periodname" column="name"/> > > <result property="kod" column="code"/> > > <result property="begdate" column="begdate"/> > > <result property="enddate" column="enddate"/> > > <result property="flag" column="flag"/> > > <association property="parent" column="par_id_period" > > resultMap="periodResuiltMap" select="selectPeriod"/> > > </resultMap> > > <select id="selectPeriod" parameterType="Long" > > resultMap="periodResultMap"> > > SELECT * FROM period WHERE id_period = #{id} > > </select> > > </mapper> > > > CREATE TABLE period > > (id_period NUMBER NOT NULL, > > periodname VARCHAR2(255), > > kod VARCHAR2(8), > > par_id_period NUMBER, > > begdate DATE, > > enddate DATE, > > flag VARCHAR2(2)) > > and bean: > > > public class Period { > > private Long id; > > private String name; > > private String code; > > private Period parent; > > private Date begDate; > > private Date endDate; > > public enum Flag { > > Y, Q, M > > } > > private Flag flag; > > get... set... > > > } > > > Thanks, > > Andrew |
| Powered by Nabble | Edit this page |
