zladidad
unread,Jan 11, 2011, 2:12:45 PM1/11/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to mybatis-user
Hi,
I was trying out a basic MyBatis (v3.0.4) feature, namely getting a
(Hash)Map from a selected DB table row. But I can't get it working.
I have the following table and data in a MySQL database:
CREATE TABLE `NotificationService` (
`player` bigint(20) unsigned NOT NULL COMMENT 'Player ID',
`appleDeviceToken` varchar(64) collate latin1_bin default NULL
COMMENT 'Device token',
`enabledAppleNotificationTypes` int(11) default '0' COMMENT 'Enabled
notification types',
`appleBadge` int(10) unsigned default '0' COMMENT 'The badge number
(number of pending events)',
`facebookId` bigint(20) unsigned default '0',
`facebookSessionKey` varchar(150) collate latin1_bin default NULL,
`facebookSettings` int(11) default '0',
`twitterFeed` varchar(15) collate latin1_bin default NULL,
`twitterPassword` varchar(30) collate latin1_bin default NULL,
PRIMARY KEY (`player`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_bin;
INSERT INTO `NotificationService` (`player`, `appleDeviceToken`,
`enabledAppleNotificationTypes`, `appleBadge`, `facebookId`,
`facebookSessionKey`, `facebookSettings`, `twitterFeed`,
`twitterPassword`) VALUES (76356, NULL, 0, 0, 2345, 0x6662534b, 1,
NULL, NULL);
I want to use MyBatis to retrieve a (Hash)Map of the values for the
single row, given the "player" primary key. So, the mapper file entry
looks like this (i hard-coded the "player" parameter in order to make
sure wrong parameter-setting usage can be ruled out as the source of
the problem):
<select id="playerSelectNotificationPlayer2" resultType="map" >
SELECT * FROM db.NotificationService
WHERE player = 76356;
</select>
In the code, i do the following:
@Test
public final void testPlayerSelectNotificationPlayer() {
SqlSession s = null;
try {
s = sessionFactory.openSession();
Object res = s.selectOne("playerSelectNotificationPlayer2");
System.out.println("RESULT IS " + res);
} finally {
if (s != null) {
s.close();
}
}
}
Which gives me the following output:
9:38:12,546 DEBUG PooledDataSource:27 - Created connection 28652556.
19:38:12,562 DEBUG Connection:27 - ooo Connection Opened
19:38:12,640 DEBUG PreparedStatement:27 - ==> Executing: SELECT *
FROM db.NotificationService WHERE player = 76356;
19:38:12,640 DEBUG PreparedStatement:27 - ==> Parameters:
19:38:12,656 DEBUG ResultSet:27 - <== Columns: player,
appleDeviceToken, enabledAppleNotificationTypes, appleBadge,
facebookId, facebookSessionKey, facebookSettings, twitterFeed,
twitterPassword
19:38:12,656 DEBUG ResultSet:27 - <== Row: 76356, null, 0, 0,
2345, fbSK, 1, null, null
RESULT IS null
19:38:12,671 DEBUG Connection:27 - xxx Connection Closed
19:38:12,671 DEBUG PooledDataSource:27 - Returned connection 28652556
to pool.
The System.out.prinltn() indicates that the returned value was "null",
even though the row was retrieved from the DB. The same happens if I
replace resultType="map" with resultType="hashmap" in the mapper file.
The problem also appears when I replace s.selectOne() with
s.selectList(), the single entry in the returned list being a "null"
value.
What am I doing wrong?
--z