Hello
I need some help with a case
Superclass specified as mapped-superclass in orm.xml:
Code:
public class SMS {
private String message;
public void setMessage(String message){
this.message = message;
}
public String getMessage(){
return message;
}
}
Entity mapped as receivedSms in orm.xml:
Code:
public class ReceivedSMS extends SMS {
private String sender;
public void setSender(String sender){
this.sender = sender;
}
public String getSender(){
return sender;
}
...
}
Entity mapped as sentSms in orm.xml:
Code:
public class SentSms extends SMS {
private String receiver;
public void setReceiver(String receiver){
this.receiver = receiver;
}
public String getReceiver(){
return receiver;
}
}
SMSRepositoryImpl:
Code:
public class SMSRepository extends JpaTemplate implements SMSRepository {
public List<SMS> getAllSMS(String cellphoneNumber){
return find("from receivedSms received, sentSms sent where received.sender = ?1 or sent.receiver = ?1");
}
In theory this query should find items both in receivedSms and sentSms that matches the specified cellphone number.
In my testcase i have a method like this:
Code:
public void testFindAllMessagesForCellphone(){
// Several messages to and from 99999999 are stored in receivedSms and sentSms
List<SMS> list = smsRepository.getAllSMS("99999999");
assertNotNull(list);
assertTrue(list.size() > 0);
// for debug
for (SMS sms : list){
System.out.println(sms.getClass().getName());
}
}
The System.out.println(sms.getClass().getName() gives a ClassCastException saying:
Code:
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to saga.sms.SMS
When i iterate like this and not using generics for my list:
Code:
for (int i = 0; i < list.size(); i++){
System.out.println(list.get(i).getClass().getName());
}
It writes out [Ljava.lang.Object;
The size of the collection is the same as the total sms's stored in sentSms and receivedSms, and from the debug messages it looks like everything is working fine. It's doing a two phased load and says that it is materializing the SentSms and ReceivedSms objects.
How can i access the real objects that i query for?
Thankful for any help i can get
/Per-Jarle