I have a problem with usage MSSQL temporary table in my app which connected to base with OpenJPA. This is a create-table script which I used to create my temporary table
create table ##EXT_DATABASE_RESULTS (
ID bigint not null identity,
RESULT_KEY uniqueidentifier not null,
CREATE_TS datetime,
ENTITY_ID uniqueidentifier not null,
primary key (ID))
Object model:
@Entity(name = "ext$DatabaseResults")
@Table(name = "##EXT_DATABASE_RESULTS", schema = "tempdb")
public class DatabaseResults {
@Id
@Persistent
@Column(name = "ID")
protected Long id;
@Column(name = "RESULT_KEY")
protected UUID resultKey;
@Column(name = "ENTITY_ID")
protected UUID entityId;}
And when I try to select some data using ext$DatabaseResults I get exception org.apache.openjpa.persistence.ArgumentException: Table "tempdb."##EXT_DATABASE_RESULTS"" given for "com.haulmont.ext.core.entity.DatabaseResults" does not exist.
I have found that this exception is thrown from org.apache.openjpa.jdbc.meta.MappingInfo#createTable besause of openjpa can't find my table.
OpenJPA won't directly work with temporary tables. I'd suggest using NativeQueries along with ResultSetMappings to map the data into your Entities.