You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Yesterday I ran into an - at first sight - obscure problem with the query()-method. Digging into it revealed what's going an.
The following query:
List<UnknownTable> l = session.query(UnknownTable.class,
"SELECT LIMIT 10 personalnr, bewerbernr, nlcode FROM mitarbeiter WHERE austrittsdatum < MDY(1,1,2018)");
results in an exception, unless the the database has a matching table name for "unknowntable":
net.sf.persism.PersismException: Could not determine a table for type: de.test.dali.persistence.UnknownTable Guesses were: [UnknownTable, UnknownTables, Unknown Table, Unknown_Table, Unknown Tables, Unknown_Tables]
If there is actually a table for "UnknownTable" the error message gets more obscure (as it was for us yesterday) - imagine you do a query with the parameter Bewerber.class and there actually is a table in the database with the same name:
net.sf.persism.PersismException: Object class de.test.dali.persistence.Bewerber was not properly initialized. Some properties not initialized by the queried columns: [bewerbernr, nlcode] Missing:[nl_code]
I didn't try it with joins, but I guess it will cause similar problems.
So what's would be expected behaviour:
at least an error message stating something like "Class name (or @Table annotation) needs to match the queried tabled" -- especially the second case left us totally clueless yesterday ...
but better: no error message but simply delivering the results of the query, independent of a match of the table name.
I think the meachanism to match table names to class names (or @Table annotations) is useful for CRUD of individual records -- but with a free query this should not be constraining the classes that can be used.
The text was updated successfully, but these errors were encountered:
I would use the @NotTable annotation for this. That's used for when you have an arbitrary query not associated to any particular table. In that case Persism doesn't look at table name and just matches up Column names. So where you want some query you need to create a Class or Record with matching property names.
Yesterday I ran into an - at first sight - obscure problem with the query()-method. Digging into it revealed what's going an.
The following query:
results in an exception, unless the the database has a matching table name for "unknowntable":
If there is actually a table for "UnknownTable" the error message gets more obscure (as it was for us yesterday) - imagine you do a query with the parameter
Bewerber.class
and there actually is a table in the database with the same name:I didn't try it with joins, but I guess it will cause similar problems.
So what's would be expected behaviour:
"Class name (or @Table annotation) needs to match the queried tabled"
-- especially the second case left us totally clueless yesterday ...I think the meachanism to match table names to class names (or
@Table
annotations) is useful for CRUD of individual records -- but with a free query this should not be constraining the classes that can be used.The text was updated successfully, but these errors were encountered: