Ok so I found the cause of the problem. ResourceStateEntity, the base class of AgentStateEntity, has a one to one mapping that is being loaded when the AgentStateEntity is retrieved from the database.
Code:
@OneToOne
@JoinColumns({
@JoinColumn(name="connectionstateconnectionforeignkey", referencedColumnName="connectionforeignkey"),
@JoinColumn(name="connectionstatepbxeventforeignkey", referencedColumnName="pbxeventforeignkey")
})
private ConnectionStateEntity connectionState;
If I remove this mapping then the error goes away. ConnectionStateEntity and it's primary key looks like this:
Code:
@Entity
@Table(name = "dbo.connectionstates")
public class ConnectionStateEntity extends ConnectState implements Serializable, IConnectionState, IDTO
{
private static final long serialVersionUID = 1L;
@EmbeddedId
private ConnectionStateEntityPrimaryKey primaryKey = null;
@ManyToOne
@JoinColumn(name = "pbxeventforeignkey", nullable = false, insertable = false, updatable = false)
private PbxEventEntity event = null;
@ManyToOne
@JoinColumn(name = "connectionforeignkey", nullable = false, insertable = false, updatable = false)
private ConnectionEntity connection = null;
}
@Embeddable
public class ConnectionStateEntityPrimaryKey implements Serializable
{
private static final long serialVersionUID = 1L;
@Column(name = "connectionforeignkey", nullable = false, insertable = true, updatable = false)
private long connectionForeignKey = 0L;
@Column(name = "pbxeventforeignkey", nullable = false, insertable = true, updatable = false)
private long pbxEventForeignKey = 0L;
}
EDIT: Ok the problem is with the order by clause:
order by events3_.primarykey asc
events3_ refers to callevents, which doesn't have a primarykey column. the two columns it does have are callforeignkey and pbxeventforeignkey
Code:
select connection0_.connectionforeignkey as connecti1_32_0_,
connection0_.pbxeventforeignkey as pbxevent2_32_0_,
connection0_.state as state3_32_0_,
connection1_.primarykey as primaryk1_31_1_,
connection1_.callforeignkey as callfore6_31_1_,
connection1_.completetime as complete2_31_1_,
connection1_.connecttime as connectt3_31_1_,
connection1_.pbxresourceforeignkey as pbxresou7_31_1_,
connection1_.starttime as starttim4_31_1_,
connection1_.talktime as talktime5_31_1_,
callentity2_.primarykey as primaryk1_23_2_,
callentity2_.talktime as talktime2_23_2_,
callentity2_.timetoabandon as timetoab3_23_2_,
callentity2_.timetoanswer as timetoan4_23_2_,
events3_.callforeignkey as callfore1_23_3_,
pbxeventen4_.primarykey as pbxevent2_7_3_,
pbxeventen4_.primarykey as primaryk1_43_4_,
pbxeventen4_.cause as cause2_43_4_,
pbxeventen4_.eventtime as eventtim3_43_4_,
pbxeventen4_.opcode as opcode4_43_4_,
pbxresourc5_.primarykey as primaryk2_45_5_,
pbxresourc5_.abbreviation as abbrevia3_45_5_,
pbxresourc5_.currentmode as currentm4_45_5_,
pbxresourc5_.description as descript5_45_5_,
pbxresourc5_.id as id6_45_5_,
pbxresourc5_.type as type1_45_5_,
pbxresourc5_.updateversion as updateve7_45_5_,
pbxresourc5_.modularmessaging as modularm8_45_5_,
pbxresourc5_.tsftime as tsftime9_45_5_,
pbxresourc5_.extensiontype as extensi10_45_5_,
pbxeventen6_.primarykey as primaryk1_43_6_,
pbxeventen6_.cause as cause2_43_6_,
pbxeventen6_.eventtime as eventtim3_43_6_,
pbxeventen6_.opcode as opcode4_43_6_
from dbo.connectionstates connection0_
inner join dbo.connections connection1_ on
connection0_.connectionforeignkey=connection1_.primarykey
inner join dbo.calls callentity2_ on
connection1_.callforeignkey=callentity2_.primarykey
left outer join callevents events3_ on
callentity2_.primarykey=events3_.callforeignkey
left outer join dbo.pbxevents pbxeventen4_ on
events3_.pbxeventforeignkey=pbxeventen4_.primarykey
inner join dbo.pbxresources pbxresourc5_ on
connection1_.pbxresourceforeignkey=pbxresourc5_.primarykey
inner join dbo.pbxevents pbxeventen6_ on
connection0_.pbxeventforeignkey=pbxeventen6_.primarykey
where connection0_.connectionforeignkey=? and
connection0_.pbxeventforeignkey=?
order by events3_.primarykey asc