Custom SQL queries in mapper xml is handled differently in mybatis generator

738 views
Skip to first unread message

Paul

unread,
Feb 4, 2011, 6:06:08 AM2/4/11
to mybatis-user
Hi,

I'm in the process of migrating from ibatis to mybatis, and I've
noticed the mybatis generator seems to behave differently. I'm
working with a 'legacy' database with a number of interesting design
'features' (i.e. bad designs). I don't have control of the database
design and it still occasionally changes. To get around some of these
quirks in the past I have added custom sql statements to the sql map
xml files. Previously when I ran ibator it would ignore any sql
statements that weren't annotated, so I could re-run the generator
without it deleting my custom statements. However, the mybatis
generator deletes all sql statements whether they are annotated or
not. Is this intentional? The ability to add custom sql statements
that returned to standard generated result maps was a nice feature of
ibator.

An example,

... more xml ...
<update id="updateByPrimaryKey"
parameterType="uk.co.spidex.isis.domain.ContractingCompany">
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do
not modify.
....
-->
.... generated sql ....
</update>
<select id="getCompaniesOfferingService"
parameterType="java.lang.Integer" resultMap="BaseResultMap">
... custom sql returning to generated company result map ...
</select>

With ibator the extra sql statement would still be there if I re-run
the generator, now it is deleted and I have to do an SVN merge to get
them back.

I'm sold on the mappers are better than DAOs argument, but I can't see
the advantage of removing this feature.

I'm using mybatis-generator-core-1.3.0.

Any help/info greatly appreciated.

Jeff Butler

unread,
Feb 4, 2011, 10:41:20 AM2/4/11
to mybati...@googlegroups.com
Hmmm...I'll have to look into this. The XML merge is supposed to work
with the generator and I thought I had tested it.

Jeff Butler

--
Sent from my mobile device

Jeff Butler

unread,
Feb 4, 2011, 3:57:20 PM2/4/11
to mybati...@googlegroups.com
I'm not seeing any problems. My testing with XML merging all works as expected.

1. Are you using eclipse, or calling from the command line or Ant or Maven?
2. Can you provide an example XML file where merging fails? You can
PM me if that would be better.

Jeff Butler

Jeff Butler

unread,
Feb 4, 2011, 4:00:13 PM2/4/11
to mybati...@googlegroups.com
Also, what JRE are you using? Is there any unusual XML parser in your
classpath?

Jeff Butler

Paul

unread,
Feb 9, 2011, 7:47:55 AM2/9/11
to mybatis-user
Thanks for the reply,

I've done some more checking and you are correct the XML does seem to
merge correctly. However, if I extend the Java mapper interface file
with a custom method, the custom method is deleted after re-running
the generator (even though it is not annotated). So my problem is
still partly there.

I'm using Sun's jdk1.6.0_21 and I'm running from a command line with -
overwrite option.

Thanks for the assistance.


Jeff Butler

unread,
Feb 9, 2011, 10:53:40 AM2/9/11
to mybati...@googlegroups.com
Are you using the Eclipse plugin? Java files can only be merged with
Eclipse. Otherwise they are overwritten or written with a unique file
name depending on the setting you specify.

Jeff Butler

Paul

unread,
Feb 10, 2011, 6:12:34 AM2/10/11
to mybatis-user
No I'm running it from the command line, whereas before I was using
the ibator plug-in. I would prefer to use the plugin, but last time I
checked the Eclipse plugin site didn't exist yet for mybatis.

Thanks for the information.

Jeff Butler

unread,
Feb 10, 2011, 11:14:05 AM2/10/11
to mybati...@googlegroups.com

Armando Pelaez

unread,
Apr 23, 2016, 11:19:52 PM4/23/16
to mybatis-user
If the Plugin is able to do it, why canno't we write the same code? Is it aveliable?
The java file merge is something awesome and i would love to configure a Gradle java run so i always merge my files.
If i canno't get to write the code, any ideas on how to configure maven to run the Eclipse mybatis generator plugin?

Jeff Butler

unread,
Apr 24, 2016, 5:15:21 PM4/24/16
to mybati...@googlegroups.com
The plugin uses Eclipse's Java parser and AST walker.  The JDK/JRE doesn't have anything like that built in.  That's why there is no merge support outside of Eclipse.

I found this recently:  http://javaparser.github.io/javaparser/.  It might fit the bill for a non-Eclipse based solution.  Hopefully I'll have some time to look at it in detail sometime soon.

Jeff Butler


--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mybatis-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jarmando

unread,
Apr 28, 2016, 2:33:12 PM4/28/16
to mybati...@googlegroups.com
Thanks for the reply is good to know. Anyways, how can i access the Eclipse
plugin to execute automatically (as an ant task for example) instead of me
having to left click and click generate? (at least while developin, executed
with Eclipse opened)

(My idea is to exec the ant task in maven each time the proyect builds (with
gradle) so i can always have my code mirroring my db. I am already doing
this with mybatis generator, but i would love to have merging capabilities)

Is that possible?



--
View this message in context: http://mybatis-user.963551.n3.nabble.com/Custom-SQL-queries-in-mapper-xml-is-handled-differently-in-mybatis-generator-tp2424482p4029409.html
Sent from the mybatis-user mailing list archive at Nabble.com.
Reply all
Reply to author
Forward
0 new messages