ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Steven A <traderj1...@gmail.com>
Subject multiple table mapping scenario.
Date Fri, 12 Jun 2009 07:57:24 GMT
Hello all, new to iBatis, here goes.

I have a table structure like this:

create table zomg_zh (
    id         int(10) not null,
    name   varchar(64) null,
    age      int(10) null,
    primary key(id),
    unique(id)
)

create table zomg_er (
    id         int(10) not null,
    name   varchar(64) null,
    age      int(10) null,
    primary key(id),
    unique(id)
)

and an object like this (brevity):

public class NotImportant {
     void setId(Long id);
     Long getId();
     void setName(String name);
     String getName();
     void setAge(Long age);
     Long getAge();

     // special stuff
     String getTableName();
     void setTableName(String name);
}

SqlMappingFile:

<sqlMap>
    <typeAlias alias="notImportant" type="com.my.ball.NotImportant" />

    <!--
     | table structure
     +-->
    <resultMap id="result" class="notImportant">
        <result property="id" column="id" />
        <result property="name" column="name" />
        <result property="age" column="age" />
    </resultMap>

    <!--
     | select all
     +-->
    <select id="readAll" resultMap="result" parameterClass="notImportant">
        select * from zomg_#tableName#  -- **** NOTICE THIS ****
    </select>

    <insert id="insert" parameterClass="notImportant">
        insert into zomg_#tableName# (
            id, name, age)
        values (
            #id#,
            #name#,
            #age#)
    </insert>
  </sqlMap>



calling getSqlMapClient().queryForList("readAll", notImportantObj); leads to
a MySQLSyntaxException because it creates a query like this: '   select *
from zomg_'zh'   '; while this exception makes perfect sense to me (it seems
natural for iBatis to surround a string with ' '); I would love to know how
to solve this problem.

So my goal here is to basically map many tables to 1 object.  There is no
inheritance that makes sense in my particular object model, which would be
the way I would think about solving this with hibernate.  Obviously I've
created a dummy example to not bring any added complexity in this example.
Is this possible to do with iBatis?

Basically I have massive amounts of data for each of these tables, or I
wouldn't be looking to do this.

Thanks,

failuser

Mime
View raw message