'Ignore Column If Not Present From Spring Entity Manager Stored Procedure ResultList
I'm working with a few different databases that all have the same stored procedure, but some have been updated while others haven't.
Suppose I have this entity:
@NamedStoredProcedureQueries(
NamedStoredProcedureQuery(
name = "getData",
procedureName = "dbo.selClientByStatus",
resultClasses = [MonitorData::class],
parameters = [
StoredProcedureParameter(name = "lowerRange", type = Int::class, mode=ParameterMode.IN),
StoredProcedureParameter(name = "upperRange", type = Int::class, mode=ParameterMode.IN),
StoredProcedureParameter(name = "connectionStatus", type = Int::class, mode=ParameterMode.IN),
StoredProcedureParameter(name = "serverID", type = String::class, mode=ParameterMode.IN),
]
)
)
@Entity
data class MonitorData(
@Id
@Column(name = "serverId")
val serverId: Int? = null,
@Column(name = "displayName")
val displayName: String? = null,
@Column(name = "providerId")
val providerId: Int? = null
)
When I call the stored procedure with:
em?.createNamedStoredProcedureQuery("getData")
?.setParameter("lowerRange", null)
?.setParameter("upperRange", null)
?.setParameter("connectionStatus", null)
?.resultList
Some databases have providerId
as a select in the stored procedure, but some don't. It's not really a necessary field, but it can help with sorting, etc. When a stored procedure doesn't select providerId
I understandably get a(n) SQLServerException
saying The column providerId is not valid
.
Is it possible to ignore that field if it doesn't exist in the resultList
?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|