Cannot join to attribute of basic type - spring

I'm writing this method statement in my repository:
Optional<Contract> findFirstByContractDate_YearOrderByContractDateDesc(Integer year);
It throws this exception when I run the app:
org.hibernate.query.criteria.internal.BasicPathUsageException: Cannot join to attribute of basic type
Looks like something is not good when getting year from localdatetime. I can implement it in other way (passing begin and end of year and comparing the contractDate) but I'd like to know what's wrong with this.

Related

solr jdbc throws and exception as if something is wrong within implementation there

I am trying to check the solr jdbc driver.
It seems to be working only with DbVisualizer & squirrelSQL.
As it is totally undocumented (properties, etc.) I've no idea what is the issue, but I keep on getting some weird error :
java.sql.SQLException which results from java.io.IOException which
results from org.noggit.JSONParser$ParserException: JSON Parse Error
char=<
It seems like internally something is going wrong there, as the engine expects JSON and receives XML.
The code is super straight forward :
Class.forName("org.apache.solr.client.solrj.io.sql.DriverImpl");
Connection conn = DriverManager.getConnection("jdbc:solr://zootest01:2181/?collection=mycol");
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery("select item_id from mycol limit 10");
The above is the most straightforward code for Java using JDBC.
The executeQuery will always throw an exception.
What is more weird is that tools like DBeaver has the same problem exactly.
I couldn't find any explanation to this behavior, unless something in the implementation is somehow hard-coded to the above 2 specific tools.

Best way to return "expected" Oracle exceptions to Java Groovy/Grails

Background:
In my Oracle database, I have plenty of database calls which can cause exceptions. I currently have exception handlers for all these, which call an error package. To cut a long story short, a raise_application_error is eventually raised, for expected errors, or a raise for unexpected errors, and this is sent back to the calling Java Groovy/Grails application layer.
So, for example, if a user enters an id and clicks search, I run a select query from the database. If the id doesn't exist, I have a NO_DATA_FOUND exception which performs a raise_application_error with a custom error message (i.e. "ID entered cannot be found.")
However, the application development team say they're struggling with this. They are trying to perform unit testing in Groovy and ideally want a variable returned. The SQL exceptions I am currently returning cause all tests to fail as it is an exception. Their code looks like this:
void nameOfProcedure() {
String result = storedProcedure.callDBProcedure(ConnectionType.MSSQL, val1, val2)
log.info "SQL Procedure query result value: "+ result
assertEquals("1", result)
}
They can add something like this above the test:
#Test (expected = SQLException.class)
But this means all returning SQLExceptions will pass, regardless of whether they are the right exceptions for the issue at hand.
Question:
What is the best solution to this issue? I'm being pressed to return variables from my exception blocks, rather than raise_application_errors - but I'm very reluctant to do this, as I've always been told this is simply terrible practice. Alternatively, they could make changes on their end, but are obviously reluctant to.
What's the next step? Should I be coding to return "expected" errors as variables, as opposed to exceptions? For example, if someone enters an ID that isn't found:
BEGIN
SELECT id
FROM table
WHERE id = entered_id
EXCEPTION
WHEN NO DATA FOUND THEN
RETURN 'ID cannot be found';
END
Or alternatively, should they be following a guide like this which advises using Hamcrest matchers to create their own custom exception property, which they can check against in their JUnit testing. What is best practice here?
You're right, it's terrible practice. It just 'wagging the dog'; they're being lazy to work good and wish you to spoil application design in order to please them.
Generally, unit test with exception returned should looks something like this:
try {
String result = callDBProcedure();
fail("Result instead of exception");}
catch (OracleSQLException e) {
assertEquals(e.errorCode, RAISE_APPLICATION_ERROR_CODE);}
catch (Throwable t) {
fail("Unexpected error");
}
They can upgrade this as they wish. For example, they can develop procedure 'call the SP and convert exception to anything they wish' and use it in their tests. But they should not affect application design outside testing. Never.

Finding only the new rows added to a table

I have the following code which is supposed to get me only the new events added to the table from the last time i checked the table.
events=#browser.table( :id =>'table_events').tbody.rows
....
some code
....
events_new=#browser.table( :id =>'table_events').tbody.rows
events=events_new - events # not working !!
Im getting the fallowing error :
undefined method `-' for #<Watir::TableRowCollection:0x007fccb9ba2358> (NoMethodError)
I understand that the "-" predicate is wrong of course, but is there a method that does what i need or do i need to go over all the TableRowCollection and find the new rows manually?
You could try converting the TableRowCollection to an array, which does support subtraction:
events = events_new.to_a - events.to_a
That will work provided the elements have a useful == method defined - and it looks like they do.
Correction: actually, because array subtraction is implemented using a hash table for efficiency (view source here if you're curious), it is not the TableRow#== method that is important but the TableRow#hash method. Fortunately, it looks like Watir implements that as well.

DbLimitExpression requires a collection argument

Does anyone have the faintest idea what this error means please and how to resolve it? All my research is drawing a blank, I can see how to set it on MSDN but it doesn't explain it in a way that explains to me what the issue is. If I remove some of my LINQ queries to set viewbag items then it seems to resolve it but the moment I set new ones and pass them into my view to generate a mail for MVCMailer it comes back. Not sure if its a viewbag issue or simply that I am calling too many linq queries to generate them to pass to the view.
I am very stuck (again)..........
Cheers,
Steve.
DbLimitExpression requires a collection argument.
Parameter name: argument
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: DbLimitExpression requires a collection argument.
Parameter name: argument
An example of the code is:
var VBSalutation = from A in context.Salutations
where A.SalutationId == policytransaction.SalutationId
select A.SalutationName;
ViewBag.Salutation = VBSalutation.FirstOrDefault();
This is repeated for various parameters and then passed to the view.
Well, I faced a similar problem and solved it. Problem was in WHERE clause: data type of left side equal operator (=) sign was not matching with data type of right side. So in your scenario:
where A.SalutationId == policytransaction.SalutationId
SalutationID of A might be an INT and SalutationId of policytransaction might be a string (This is how it was in my case).
I solved it by assigning policytransaction.SalutationId to an Int variable and using it:
int myIntVariable = Convert.ToInt16(policytransaction.SalutationId);
...//some code here
where A.SalutationId == myIntVariable;
Please also note that you cannot directly cast your variables directly in Linq else you'll get an error "LINQ to Entities does not recognize the method". You'll have to use a temp variable and then apply the where clause.
Try ViewBag.Salutation = VBSalutation.SingleOrDefault();

Refactor my ruby snippet so it doesn't look like C anymore: method(method(param))

I have a class which uses a connection object to send the request data created by a request_builder object.
The code looks like this:
connection.send_request(request_builder.build_request(customer))
This in turn is called by
build_report(customer, connection.send_request(request_builder.build_request(customer)))
Ugly! Any ideas on how to make it more expressive? Usually in ruby and OOP we chain objects like this: "string".make_it_bigger.flash_it.send
It's code, that how it looks. But you can make yourself a favour by not trying to cram everything together on one line:
request = request_builder.build_request(customer)
response = connection.send_request(request)
report = build_report(customer, response)
if you told us more about your code base we might be able to suggest something else, but you don't give us very much to go on. What does the request_builder object do? Does connection.send_request(...) return a response? Why does a report need a customer and a response (assuming that's what is returned by connection.send_request(...)), and so on.
build_report(customer, request_builder.build_request(customer).send_over(connection))

Resources