I have two table like this :
CREATE TABLE `bet_game` (
`gameId` int(6) unsigned NOT NULL auto_increment,
`subjectcode` varchar(25) NOT NULL default '',
`year` varchar(4) default NULL,
`month` varchar(4) default NULL,
`day` varchar(4) default NULL,
`active` int(1) default NULL,
`gamename` varchar(50) NOT NULL default '',
`winnerid` varchar(6) default NULL,
PRIMARY KEY (`gameId`)
) TYPE=MyISAM;;
CREATE TABLE `bet_subject` (
`Subjectid` int(10) unsigned NOT NULL auto_increment,
`SubjectCode` varchar(25) NOT NULL default '',
`Subjectname` varchar(50) default '0',
`Parentid` int(10) unsigned default '0',
`orderid` int(10) unsigned default '0',
`IsLastLevel` int(1) default NULL,
PRIMARY KEY (`Subjectid`)
) TYPE=MyISAM;;
each subject has many games.Now I create a class:
public class BetGame {
private java.lang.Integer gameid;
......
private BetSubject betSubject = null;
......
}
public class BetSubject {
private java.lang.Integer subjectid;
......
}
In file BetGame.hbm.xml:
<many-to-one name="betSubject" column="subjectcode"
class="betting.db.BetSubject"/>
At last I code like this:
Criteria critSub = session.createCriteria(BetSubject.class);
critSub.add(Expression.eq("subjectcode", subjectCode));
BetSubject subject = (BetSubject) critSub.list().get(0);
Criteria crit = session.createCriteria(BetGame.class);
crit.add(Expression.eq("betSubject", subject));
List cats = crit.list();
there throw an exception.Where a made mistake?3Q
|