Hello.
I am getting list of null objects from the table. Actually the data is there and the size of list getting correctly but will null objects.
Mapping file
Code:
<class name="com.alu.pnm.eam.beans.ImmediateAlert" table="immediatealert" lazy="false">
<composite-id>
<key-property name="customer" length="6525" column ="Customer" />
<key-property name="toAddr" length="6525" column ="ToAddr" />
<key-property name="subject" column ="Subject"/>
<key-property name="message" column ="Message"/>
<key-property name="callBackURL" column ="CallBackURL"/>
<key-property name="alertType" type="int" column="AlertType" />
<key-property name="event" length="6525" column ="Event" />
<key-property name="eventDate" column ="EventDate"/>
<key-property name="eventTime" column ="EventTime"/>
<key-property name="elementType" column ="ElementType"/>
<key-property name="elementName" column ="ElementName"/>
<key-property name="subElement" column ="SubElement"/>
<key-property name="eventName" column ="EventName"/>
<key-property name="eventType" column ="EventType"/>
<key-property name="severity" column ="Severity"/>
<key-property name="matchedRuleIDs" column ="MatchedRuleIDs"/>
</composite-id>
<property name="numberOfRetries" type="int" column ="NumberOfRetries"/>
<property name="isMessageSent" not-null="true">
<column sql-type="BOOLEAN" not-null="true" name="IsMessageSent" />
</property>
Table
Code:
CREATE TABLE `immediatealert` (
`Customer` varchar(255) NOT NULL DEFAULT '',
`ToAddr` text,
`Subject` varchar(255) NOT NULL DEFAULT '',
`Message` text,
`CallBackURL` text,
`AlertType` int(11) NOT NULL DEFAULT '0',
`IsMessageSent` tinyint(1) NOT NULL,
`NumberOfRetries` int(11) DEFAULT NULL,
`Event` varchar(255) NOT NULL DEFAULT '',
`EventDate` varchar(255) NOT NULL DEFAULT '',
`EventTime` varchar(255) NOT NULL DEFAULT '',
`ElementType` varchar(255) NOT NULL DEFAULT '',
`ElementName` varchar(255) NOT NULL DEFAULT '',
`SubElement` varchar(255) NOT NULL DEFAULT '',
`EventName` varchar(255) NOT NULL DEFAULT '',
`EventType` varchar(255) NOT NULL DEFAULT '',
`Severity` varchar(255) NOT NULL DEFAULT '',
`MatchedRuleIDs` varchar(255) NOT NULL DEFAULT '',
`RuleID` bigint(20) DEFAULT NULL,
`CreatedDateTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
`id` bigint(20) DEFAULT NULL,
PRIMARY KEY (`Customer`,`Subject`,`AlertType`,`Event`,`EventDate`,`EventTime`,`ElementType`,`ElementName`,`SubElement`,`EventName`,`EventType`,`Severity`,`MatchedRuleIDs`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
Java Code
Code:
List<ImmediateAlert> immedAlrtList = new ArrayList<ImmediateAlert>();
if(alertType != 0){
try{
session = sessionFactory.openSession();
Criteria criteria = session.createCriteria(ImmediateAlert.class);
criteria.add(Restrictions.eq("alertType", alertType));
criteria.add(Restrictions.eq("isMessageSent", false));
// Query query = session.createQuery(" from ImmediateAlert where alertType = "+alertType+" AND isMessageSent = 0 ");
if(session!=null)
immedAlrtList = criteria.list();
if(immedAlrtList != null){
return immedAlrtList;
Error: Getting list of null object with correct size.
size=3
[null,null,null]
What is the problem in the code?