I have searched all over stackoverflow.com but I have not found this discussion.
I know my problem, I was just wondering if JPA can handle this in any way without a lot of work...
What I have is an @Entity that I want to use with multiple SQL-Native-Queries.
@Entity
public class TestEntity {
@Id
private String ID;
private String ID1;
private String ID2;
private String ID3;
}
Names in the database are equal to Field names.
I then have two selects:
SELECT ID1, ID2 from DATABASE;
SELECT ID2 from DATABASE;
And two native queries for those selects:
@Query(value = "SELECT ID2 from DATABASE", nativeQuery = true)
List<TestEntity> testNativeQuery ();
And the Error I get:
[ERROR] 2021-11-30 10:37:20 [main] [SqlExceptionHelper] The column name ID1 is not valid.
How could I tell JPA that if it does not find the Column name that it should just replace it will
null ?
Would that be so difficult?
Some extra details:
I am using a Stored Procedure - which means I can not change the Query - The Stored Procedures are maintained by someone else.
Stored procedure (which works):
@Query(value = "STORED_PROC :a, :b", nativeQuery = true)
List<List<String>> execStoredProc(@Param("a") String a, @Param("b") String b);
Stored procedure that does not work, because I have more fields in the entity that the Procedure return, because I need those fields in other stored procedures:
@Query(value = "STORED_PROC :a, :b", nativeQuery = true)
List<TestEntity> execStoredProc(@Param("a") String a, @Param("b") String b);
When I remove those field the function works - but I need those fields in other part of my program - and I hoped I could use the same @Entity
Database I am using is MSSQL Database:
driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
>` I find it rather annoying though - since I have a well organised @Entity and someone has just omitted one Field from a Stored Procedure I want to use - I do not know why does it need to Fail and Throw an Exception instead of just filling that Field with a Null value? Or maybe i could define the @Entity if the Column is not found then it is "null" or "columnNotFound" or sth? Why would that not be possible? What kind of inconsistencies could arise in that case?
– Jack Nov 30 '21 at 17:33