龍子 发表于 2016-11-25 06:16:31

Tree structure handling by MyBatis

  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 
页: [1]
查看完整版本: Tree structure handling by MyBatis