I'm currently using ibatis to returns some pojos and everything works great.
My question is:
I have to return 1 row from a table, just like 3 fields, and I don't want to create a pojo for it. I just want to run the query and get the 3 values. Is there any easy way to do this without create a special java object just for this?
views:
1146answers:
3in IBatis.NET we use Hashtable when we need more than one value from a query.
<resultMap id="ResultMap1" class="Hashtable">
<result column="FirstName" property="FirstName" type="string" />
<!-- shows up as "FirstName" in the Hashtable -->
<result column="LastName" property="LastName" type="string" />
<!-- shows up as "LastName" in the Hashtable -->
</resultMap>
I'm not aware of any method for doing what you are asking; the specific purpose of iBATIS is to automate the mapping of relational models to classes.
I'm not sure what you're trying to do, but if you have meaningful data, you should be able to map to an object of some sort, even if the object will be short-lived. I'm guessing that you need some logic based on the values fetched by your query? If that's the case, create a new POJO, map the query to it and then move the logic into your new POJO instead of wherever it is now. This will make the code much cleaner and easier maintain.
If you're just trying to pull back raw data without mapping to a class, you probably need to give your design a second look.
(I know that's not the answer you're looking for . . . sorry.)