You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by vinays84 <vi...@hotmail.com> on 2007/06/14 18:28:32 UTC

New to iBatis

Hi, I'm trying to learn iBatis SQL Maps. I've gone through the basic tutorial
provided on the iBatis site. The tutorial only deals with one table and
doesn't explain how to handle several tables with links. Is there a simple
tutorial out there that handles this?

Thanks
-- 
View this message in context: http://www.nabble.com/New-to-iBatis-tf3922862.html#a11123809
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Re: Ibatis & Java Web Start

Posted by Brandon Goodin <br...@gmail.com>.
Anytime, just let your professional friends know about me. I'm available to
hire for a reasonable consulting fee :)

Brandon Goodin

On 6/14/07, Adnan Atic <Ad...@hilton.com> wrote:
>
>  That was the problem.
> I had :
> <security>
>   <j2ee-application-client-permissions/>
> </security>
>
> which apparently wasn't enough. After I changed it to <all-permissions> it
> worked fine.
>
>
> Thanks!
>
>  ------------------------------
> *From:* Brandon Goodin [mailto:brandon.goodin@gmail.com]
> *Sent:* Thursday, June 14, 2007 2:03 PM
> *To:* user-java@ibatis.apache.org
> *Subject:* Re: Ibatis & Java Web Start
>
> Greetings Adnan,
>
> It may be an issue with how you have JavaWebStart configured. It sounds to
> me as though you do not have your security permissions configured correctly.
> Be sure you have the following security configuration in your jnlp file.
> ...
>   <security>
>       <all-permissions/>
>   </security>
> ...
>
> Brandon
>
> On 6/14/07, Adnan Atic < Adnan_Atic@hilton.com> wrote:
> >
> > Hi,
> > I am trying to distribute an app via java web start, but am having
> > difficulties with JWS not parsing my sql config files properly. I use
> > Ibatis2 with ibatis DAO Framework.
> > Right before I load my dao.xml config file I set default class loader :
> >
> >                 Resources.setDefaultClassLoader (
> > MyClass.class.getClassLoader() );
> >                 Reader reader =
> > Resources.getResourceAsReader("dao.xml");
> >                 daoManager = DaoManagerBuilder.buildDaoManager(reader);
> >
> > When I try to run it from jws I get this error:
> >
> > SEVERE: com.ibatis.dao.client.DaoException: Error while configuring
> > DaoManager.  Cause: java.lang.RuntimeException: Error occurred.  Cause:
> > com.ibatis.common.xml.NodeletException: Error parsing XML.  Cause:
> > java.lang.RuntimeException: Error parsing XPath '/sqlMapConfig/sqlMap'.
> > Cause: com.ibatis.common.xml.NodeletException: Error parsing XML.
> > Cause: java.lang.RuntimeException: Error parsing XPath
> > '/sqlMap/resultMap/result'.  Cause:
> > java.security.AccessControlException: access denied
> > (java.lang.RuntimePermission accessDeclaredMembers)
> >
> > Does anyone know if it is even possible to use ibatis dao framework from
> > java web start?
> >
> > Thanks
> >
> >
>

RE: Ibatis & Java Web Start

Posted by Adnan Atic <Ad...@hilton.com>.
That was the problem.
I had :
<security>
  <j2ee-application-client-permissions/>
</security>
 
which apparently wasn't enough. After I changed it to <all-permissions>
it worked fine.
 
 
Thanks!

________________________________

From: Brandon Goodin [mailto:brandon.goodin@gmail.com] 
Sent: Thursday, June 14, 2007 2:03 PM
To: user-java@ibatis.apache.org
Subject: Re: Ibatis & Java Web Start


Greetings Adnan,

It may be an issue with how you have JavaWebStart configured. It sounds
to me as though you do not have your security permissions configured
correctly. Be sure you have the following security configuration in your
jnlp file. 
...
  <security>
      <all-permissions/>
  </security>
...

Brandon


On 6/14/07, Adnan Atic < Adnan_Atic@hilton.com
<ma...@hilton.com> > wrote: 

	Hi,
	I am trying to distribute an app via java web start, but am
having 
	difficulties with JWS not parsing my sql config files properly.
I use
	Ibatis2 with ibatis DAO Framework.
	Right before I load my dao.xml config file I set default class
loader :
	
	                Resources.setDefaultClassLoader (
	MyClass.class.getClassLoader() );
	                Reader reader =
	Resources.getResourceAsReader("dao.xml");
	                daoManager =
DaoManagerBuilder.buildDaoManager(reader);
	
	When I try to run it from jws I get this error: 
	
	SEVERE: com.ibatis.dao.client.DaoException: Error while
configuring
	DaoManager.  Cause: java.lang.RuntimeException: Error occurred.
Cause:
	com.ibatis.common.xml.NodeletException: Error parsing XML.
Cause:
	java.lang.RuntimeException: Error parsing XPath
'/sqlMapConfig/sqlMap'.
	Cause: com.ibatis.common.xml.NodeletException: Error parsing
XML.
	Cause: java.lang.RuntimeException: Error parsing XPath
	'/sqlMap/resultMap/result'.  Cause: 
	java.security.AccessControlException: access denied
	(java.lang.RuntimePermission accessDeclaredMembers)
	
	Does anyone know if it is even possible to use ibatis dao
framework from
	java web start?
	
	Thanks 
	
	



Re: Ibatis & Java Web Start

Posted by Brandon Goodin <br...@gmail.com>.
Greetings Adnan,

It may be an issue with how you have JavaWebStart configured. It sounds to
me as though you do not have your security permissions configured correctly.
Be sure you have the following security configuration in your jnlp file.
...
  <security>
      <all-permissions/>
  </security>
...

Brandon

On 6/14/07, Adnan Atic <Ad...@hilton.com> wrote:
>
> Hi,
> I am trying to distribute an app via java web start, but am having
> difficulties with JWS not parsing my sql config files properly. I use
> Ibatis2 with ibatis DAO Framework.
> Right before I load my dao.xml config file I set default class loader :
>
>                 Resources.setDefaultClassLoader(
> MyClass.class.getClassLoader() );
>                 Reader reader =
> Resources.getResourceAsReader("dao.xml");
>                 daoManager = DaoManagerBuilder.buildDaoManager(reader);
>
> When I try to run it from jws I get this error:
>
> SEVERE: com.ibatis.dao.client.DaoException: Error while configuring
> DaoManager.  Cause: java.lang.RuntimeException: Error occurred.  Cause:
> com.ibatis.common.xml.NodeletException: Error parsing XML.  Cause:
> java.lang.RuntimeException: Error parsing XPath '/sqlMapConfig/sqlMap'.
> Cause: com.ibatis.common.xml.NodeletException: Error parsing XML.
> Cause: java.lang.RuntimeException: Error parsing XPath
> '/sqlMap/resultMap/result'.  Cause:
> java.security.AccessControlException: access denied
> (java.lang.RuntimePermission accessDeclaredMembers)
>
> Does anyone know if it is even possible to use ibatis dao framework from
> java web start?
>
> Thanks
>
>

Ibatis & Java Web Start

Posted by Adnan Atic <Ad...@hilton.com>.
Hi,
 I am trying to distribute an app via java web start, but am having
difficulties with JWS not parsing my sql config files properly. I use
Ibatis2 with ibatis DAO Framework. 
Right before I load my dao.xml config file I set default class loader :

		Resources.setDefaultClassLoader(
MyClass.class.getClassLoader() );
		Reader reader =
Resources.getResourceAsReader("dao.xml");
		daoManager = DaoManagerBuilder.buildDaoManager(reader);

When I try to run it from jws I get this error:

SEVERE: com.ibatis.dao.client.DaoException: Error while configuring
DaoManager.  Cause: java.lang.RuntimeException: Error occurred.  Cause:
com.ibatis.common.xml.NodeletException: Error parsing XML.  Cause:
java.lang.RuntimeException: Error parsing XPath '/sqlMapConfig/sqlMap'.
Cause: com.ibatis.common.xml.NodeletException: Error parsing XML.
Cause: java.lang.RuntimeException: Error parsing XPath
'/sqlMap/resultMap/result'.  Cause:
java.security.AccessControlException: access denied
(java.lang.RuntimePermission accessDeclaredMembers)

Does anyone know if it is even possible to use ibatis dao framework from
java web start?

Thanks


Re: New to iBatis

Posted by Graeme J Sweeney <ib...@gjsweeney.com>.
On Thu, 14 Jun 2007, vinays84 wrote:

>
> Hi, I'm trying to learn iBatis SQL Maps. I've gone through the basic tutorial
> provided on the iBatis site. The tutorial only deals with one table and
> doesn't explain how to handle several tables with links. Is there a simple
> tutorial out there that handles this?

Not a tutorial but look at the 'Result Maps' section of the developer's 
guide.

-- 
Graeme -

Re: New to iBatis

Posted by Nathan Maves <na...@gmail.com>.
If you are looking for more documentation pick up the iBATIS in Action book
by manning.

I highly recommend it.

Nathan

On 6/14/07, Brandon Goodin <br...@gmail.com> wrote:
>
> Shameless plug:
> http://www.manning.com/begin/
>
> Apart from that I would recommend you read the SQL Devleoper docs:
> http://ibatis.apache.org/docs/java/pdf/iBATIS-SqlMaps-2_en.pdf
>
> "doesn't explain how to handle several tables with links"
> links? do you mean joins?
>
> Remember this... with iBATIS you are mapping *results* to an object not
> *tables*. So, you would map a sql statement that joins several tables in the
> same way you would map a sql statement that queries one table. There is an
> exception when you make use of the groupBy functionality for dealing with
> N+1. It's all in the dev guide.
>
> Brandon
>
> On 6/14/07, vinays84 <vi...@hotmail.com> wrote:
> >
> >
> > Hi, I'm trying to learn iBatis SQL Maps. I've gone through the basic
> > tutorial
> > provided on the iBatis site. The tutorial only deals with one table and
> > doesn't explain how to handle several tables with links. Is there a
> > simple
> > tutorial out there that handles this?
> >
> > Thanks
> > --
> > View this message in context: http://www.nabble.com/New-to-iBatis-tf3922862.html#a11123809
> >
> > Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
> >
> >
>

Re: New to iBatis

Posted by vinays84 <vi...@hotmail.com>.
Just as only a single object can be passed in for the return class, can only
a single object be passed in for a parameter class? Consider the query:

SELECT movie_name FROM movies WHERE release_date between #value1# AND
#value2#

Could I pass in two dates as parameters, or would I have to create a class
containing value1 and value2 as properties. (this class obviously would be
created solely for this one query).
-- 
View this message in context: http://www.nabble.com/New-to-iBatis-tf3922862.html#a11145189
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Re: New to iBatis

Posted by Gwyn Evans <gw...@gmail.com>.
On Friday, June 15, 2007, 3:40:39 PM, vinays84 <vi...@hotmail.com> wrote:

> I apologize if I'm asking questions that are answered in the dev guide, I'm
> just trying to gain a quick understanding. 

> So, if I have an object defined for a specific table, then I want to include
> a query which involves another table, I'd have to expand my original object
> to incorporate the additional columns, taking away its table specific
> status?

Yes, in short. As Brandon says, you're mapping the *result* of a
query, so if you use a different result, then you (probably) need a
different object. Using a Map might let you side-step that, although
you're trading one thing for another there.

> How would one handle queries not known at time of development (for instance
> for ad-hoc reporting)?

> Does the SQL Maps framework go hand in hand with the DAO framework? i.e.
> Should I be learning the DAO framework to properly use SQL Maps.

Well, you need something, but not specifically the DAO framework - In
fact, I'd suggest looking at the Spring DAO rather than the Ibatis
DAO.

Another thing that you might want to take a look at, once you've got a
basic setup working, is the Abator utility. That examines a DB table
and produces various of the files needed to use iBATIS on it, but
might be a bit unclear if you've not got the context that creating a
basic 'by-hand' setup will have given you.

/Gwyn


Re: New to iBatis

Posted by vinays84 <vi...@hotmail.com>.
I apologize if I'm asking questions that are answered in the dev guide, I'm
just trying to gain a quick understanding. 

So, if I have an object defined for a specific table, then I want to include
a query which involves another table, I'd have to expand my original object
to incorporate the additional columns, taking away its table specific
status?

How would one handle queries not known at time of development (for instance
for ad-hoc reporting)?

Does the SQL Maps framework go hand in hand with the DAO framework? i.e.
Should I be learning the DAO framework to properly use SQL Maps.

Thank you,
Vinay


bgoodin wrote:
> 
> Shameless plug:
> http://www.manning.com/begin/
> 
> Apart from that I would recommend you read the SQL Devleoper docs:
> http://ibatis.apache.org/docs/java/pdf/iBATIS-SqlMaps-2_en.pdf
> 
> "doesn't explain how to handle several tables with links"
> links? do you mean joins?
> 
> Remember this... with iBATIS you are mapping *results* to an object not
> *tables*. So, you would map a sql statement that joins several tables in
> the
> same way you would map a sql statement that queries one table. There is an
> exception when you make use of the groupBy functionality for dealing with
> N+1. It's all in the dev guide.
> 
> Brandon
> 
> On 6/14/07, vinays84 <vi...@hotmail.com> wrote:
>>
>>
>> Hi, I'm trying to learn iBatis SQL Maps. I've gone through the basic
>> tutorial
>> provided on the iBatis site. The tutorial only deals with one table and
>> doesn't explain how to handle several tables with links. Is there a
>> simple
>> tutorial out there that handles this?
>>
>> Thanks
>> --
>> View this message in context:
>> http://www.nabble.com/New-to-iBatis-tf3922862.html#a11123809
>> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/New-to-iBatis-tf3922862.html#a11140943
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Re: New to iBatis

Posted by Brandon Goodin <br...@gmail.com>.
Shameless plug:
http://www.manning.com/begin/

Apart from that I would recommend you read the SQL Devleoper docs:
http://ibatis.apache.org/docs/java/pdf/iBATIS-SqlMaps-2_en.pdf

"doesn't explain how to handle several tables with links"
links? do you mean joins?

Remember this... with iBATIS you are mapping *results* to an object not
*tables*. So, you would map a sql statement that joins several tables in the
same way you would map a sql statement that queries one table. There is an
exception when you make use of the groupBy functionality for dealing with
N+1. It's all in the dev guide.

Brandon

On 6/14/07, vinays84 <vi...@hotmail.com> wrote:
>
>
> Hi, I'm trying to learn iBatis SQL Maps. I've gone through the basic
> tutorial
> provided on the iBatis site. The tutorial only deals with one table and
> doesn't explain how to handle several tables with links. Is there a simple
> tutorial out there that handles this?
>
> Thanks
> --
> View this message in context:
> http://www.nabble.com/New-to-iBatis-tf3922862.html#a11123809
> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>
>

Re: New to iBatis

Posted by Larry Meadors <lm...@apache.org>.
Man, what a can of worms this is..but it's great to see someone asking
these questions up-front, so I'll give it a shot, then give you my
opinion.

You might want to get comfortable, this is a long one. :)

> With Hibernate, the entire data model is mapped out for
> the application, which can initially take a while and
> have a lot of configuration, but once complete, will
> allow the developer to access the update the data model
> as the application develops with any specific queries
> that they see fit, without adding any extra POJOS or
> configuration code.

This is partially true - yes, you will need to map all of your
database objects to your java objects. This is not a terribly onerous
task, because there are some decent code generation tools that do much
of it for you.

The part that may be misleading here is that as the data/object models
mutate, both sides must mutate in perfect synchronization because it
is a 1-1 match between your data model and your object model.

In addition, as you add or move fields in your data model or object
model, the option to auto-generate the mapping degenerates.

> iBatis, on the other hand, is much simpler to set up,
> but configuration and java code (POJOS and DAOS) will
> have to be added as more queries are added to the
> application because each result class will have to be
> specifically designed for the individual query.

I think iBATIS will be simpler to set up, and you will need to add
some XML and SQL for your application.

Not every query will require a bean, and I think that most iBATIS
users generally use it to map database objects to java objects in a
way that is similar to ORM. For example, in a system I am working on,
there are User and Customer and Order beans that match the database
fields.

However, in many cases, I just need to display information from
multiple tables, so I'll use a hashmap to fetch related data. It's a
fast and easy way to get data, and requires very little code
(essentially the SQL, and one line to run it).

I was an early adapter of ORM, and quickly learned that as my
application grew, and my data access needs moved beyond 'select * from
employee', I needed to write custom queries.

Using hibernate, I had to do that in Java code using either HQL (the
query language of choice for Hibernate), or SQL (which was translated
into HQL...then back to SQL to be executed). To create a query, I had
to concatenate strings to build my query right in my Java code. This
made it nearly impossible to optimize queries, because they were
embedded in a sea if if(){} blocks, and were not easy to extract and
run outside of the application. Because the SQL was all generated, it
made it very difficult to pass to a DBA for optimization. My DBA did
not like my application much.

Using iBATIS, I do that in an XML file using SQL. For complex queries,
I use dynamic SQL which allows me to do 99% of what is needed. I can
also take SQL to a DBA (or any other SQL smart person) and have them
help optimize it.

There are also cases where your database and object models *don't*
match perfectly. In one system that I am working on, there are some
non-trivial calculations that are used to determine prices based on
both the product and the customer - some customers get lower prices on
some products than others. For that reason, the base price of a
product is stored, but whenever we need to get an actual price, we use
a database function to get it, like this: select price(product.price,
customer.id).

So the price on my product bean is never the price stored in the
database, but always calculated. If we were forced to map the database
to the object model, this would require creating a table or view that
stored the price at the customer+product level. We would also need to
find a way to ensure that the price in that table was always correct.

That brings up my main complaint about ORM.

In every system that I have worked on in the last 20 years, there are
two statements that are invariably true:
1) the only value is in the data
2) the data will outlive the code

The systems that access business data only have value because they
simplify access to the real value, which is the data. The code without
the data is like a car without gasoline - a bright shiny pile of
useless parts.

With those two thoughts in mind, every single ORM tool that I have
ever used requires that I corrupt my database to fit the object model
because it will make development simpler.

To put that in different terms, they force me to decrease the value of
the only thing in the entire system that has intrinsic value (the
data) to  simplify the development of tools (the part with no value).

That's just a retarded idea.

Larry

RE: New to iBatis

Posted by Chris Lamey <cl...@localmatters.com>.
Hello,

I've been using iBATIS as the db interface for APIs that are used by many different kinds of clients for almost two years now.

When I get a request for a new piece of functionality, I first try to implement it using only Java and the Abator generated classes.  A good chunk of the "no brainer" work can be handled this way without writing any new SQL or touching the XML.

If the functionality does require new SQL, I generally try to make the SQL return something that can be used by an Abator generated result map or a simple grouping result map using the Abator generated classes. 

For queries with results that don't map well to the Abator classes, a good chunk end up being scalar values (string or int) or to lesser degree a Map.  If that doesn't work then I'll go to a RowHandler with a Map result class.  These RowHandler queries make up a small percentage of my iBATIS SQL but generally are the most complicated and performance aware SQL I have.  I should probably write more complicated result maps in the sql map XML, but I find it much easier to handle a Map in Java than group things together in XML.

I guess what I'm saying is that if your data model is static, your model objects will be static too and you can reuse them in different sql maps.

My experience with Hibernate is that it's fast and easy to get going out of the box and much more OO friendly, but you spend all your time reverse engineering Hibernate to figure out what its doing when against the RDBMS.  If you don't have high performance SQL requirements and you have a small dataset, then Hibernate might be all you need.

For me, iBATIS takes a little more up front time because you don't automatically get joins or CRUD (although Abator goes a long way with the CRUD handling).  But you have complete control over what gets run when, which makes all the difference for me.  I recently wrote an app in a few weeks that had to deal with 30M+ row tables and knowing exactly what is running when is required for that kind of thing.

But then, in the impedance mismatch war, I'm OK with favoring the relational model because I know how to make it scale and I know it'll be around in 10 years when we're all writing Ruby clients;)

Cheers,
Chris

-----Original Message-----
From: vinays84 [mailto:vinays84@hotmail.com]
Sent: Sun 6/17/2007 3:15 PM
To: user-java@ibatis.apache.org
Subject: RE: New to iBatis
 

Thanks for all the replies. I'd like to quickly compare using iBatis vs.
Hibernate. I'm not an expert on either, so please correct any false
assumptions I make:

With Hibernate, the entire data model is mapped out for the application,
which can initially take a while and have a lot of configuration, but once
complete, will allow the developer to access the update the data model as
the application develops with any specific queries that they see fit,
without adding any extra POJOS or configuration code.

iBatis, on the other hand, is much simpler to set up, but configuration and
java code (POJOS and DAOS) will have to be added as more queries are added
to the application because each result class will have to be specifically
designed for the individual query.

Please edit/add anything that you think so I may get a proper understanding
of the differences between the two frameworks.

Thanks!
-- 
View this message in context: http://www.nabble.com/New-to-iBatis-tf3922862.html#a11167014
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.



RE: New to iBatis

Posted by vinays84 <vi...@hotmail.com>.
Thanks for all the replies. I'd like to quickly compare using iBatis vs.
Hibernate. I'm not an expert on either, so please correct any false
assumptions I make:

With Hibernate, the entire data model is mapped out for the application,
which can initially take a while and have a lot of configuration, but once
complete, will allow the developer to access the update the data model as
the application develops with any specific queries that they see fit,
without adding any extra POJOS or configuration code.

iBatis, on the other hand, is much simpler to set up, but configuration and
java code (POJOS and DAOS) will have to be added as more queries are added
to the application because each result class will have to be specifically
designed for the individual query.

Please edit/add anything that you think so I may get a proper understanding
of the differences between the two frameworks.

Thanks!
-- 
View this message in context: http://www.nabble.com/New-to-iBatis-tf3922862.html#a11167014
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.