Ebean query seems to stop execution - java

I am trying to do a fairly simple Ebean query:
Long articleId = Long.parseLong(dataFetchingEnvironment.getArgument("id"));
System.out.println("Article ID");
System.out.println(articleId);
Article article = DB.find(Article.class).where().eq("id", articleId).findOne();
System.out.println("Article");
System.out.println(article);
Article ID prints to the console, articleId prints to the console
However everything after the query does not. Absolutely no logging at all.
I've tried to enable a logback.xml on all of the queries, I'm not seeing any errors.
What could be going on here? Clearly there's some problem going on that is not being made available for me to see - how do I debug this?

Apparently something like this works:
Article article = DB.find(Article.class)
.select("id, title, body").where().eq("id", articleId)
.findOne();
System.out.println("Article");
System.out.println(article);
Not entirely sure what the difference is, as the Ebeans documentation is a little sparse, but this works for me

see your log , io.ebean.SQL - txn[txnNum] -> your query , io.ebean.SUM - txn[txNum] -> find bean or not
if find -> row[1] :
io.ebean.SUM - txn[txNum] FindBean type[beanType] origin[DrFzdL.A.A] exeMicros[num] rows[1] bind[beanId, ]
if not find -> row[0] :
io.ebean.SUM - txn[txNum] FindBean type[beanType] origin[DrFzdL.A.A] exeMicros[num] rows[0] bind[beanId, ]

Related

Extra unwanted backslash in Morphia Query object

I'm using Morphia 1.5.2 (Java 8) as a driver for MongoDB (V4.x), trying to use Search for a phrase, so my code looks like :
datastore.find(myEntity).disableValidation().search("\\\"" + textToFilter + "\\\"");
Debug looks good, but in running time the query is being sent with the three backslashes instead of just one, and the query return 0 results.
What am I missing? thanks!
actual generated query: "$text" : { "$search" : "\\\"filteredText\\\"" }
try this:
datastore.find(myEntity).disableValidation().search("\"" + textToFilter + "\"");
Copied and pasted from the official github issue tracker at https://github.com/MorphiaOrg/morphia/issues/1453 . I would have proposed this as an edit to a previous answer, as a reasonable person would have, but the moderators decided to delete the answer instead. Hope you weren't too delayed in getting your answer.
datastore.find(myEntity).disableValidation().search("\"" + textToFilter + "\"");
Thanks #evanchooly !

spring MongoOperation could get record count but could not get the corresponding results to the same Query

I'm recently working with the latest spring-boot-1.2.3.RELEASE, with spring-core 4.1.6, spring-data-commons-1.9.2.RELEASE, spring-data-mongodb-1.6.2.RELEASE.
In my case, I'd written something like this:
java.util.List<Tag> records = new java.util.ArrayList<Tag>();
records.count = tagRepos.countTags(query);
if (LOG.isDebugEnabled()) LOG.debug("[getTags] count -> {}", records.count);
if(records.count > 0){
records.records = tagRepos.findTags(query);
if (LOG.isDebugEnabled()) LOG.debug("[getTags] records -> {}", records.records);
}
return records;
And the result above prints out:
[getTags] count -> 2
[getTags] records -> []
No matter the Query object contains criteria or not, the results both the same.
I'd searched for the same situation for a long time but with no luck. Any one has encounter the same problem? I could figure out the problem is on the MongoTemplate#find method, but I could not work out what is the problem is by the time. Could any one help me out ? Thanks.
After some debug I could figure out the problem is happened on the pagination. I'd set page 1 as the first page, but I found spring-data use index 0 as the first page, causing me always try to fetch the second page contents which is not as my expect. So the code is doing very well, that's a good news.

Elasticsearch similar documents in Java

I'm doing a website (an auction website) using java. I have one page to show the product in auction and I want to show 10 similar products.
To perform the search I'm using elasticsearch (by using the elasticsearch java implementation dadoonet).
One requirement I have is to show only the 10 similar documents that has date > now.
I say the elasticsearch documentation and I found the query "More like this" but first I'm not getting this to work using:
new MoreLikeThisRequest("auction").searchSize(size).id(productId + "").fields(new String[] { "name", "description", "brand" }).type("string");
Because is always showing the error:
org.elasticsearch.index.engine.DocumentMissingException: [_na][_na] [string][2]: document missing
And I'm not find the way to filter the date.
Someone can point me on the right way to do this?
thks
My best bet would be that you have the wrong id and I also see that you are missing the type. To use more like this, you have to provide the document to use. This is defined by the combination of index,type and id. If you do not specify the document right, elasticsearch cannot find the document and that is most probably why you get the document missing message.
In java I would do something like this:
FilteredQueryBuilder queryBuilder =
new FilteredQueryBuilder(
QueryBuilders.matchAllQuery(),
FilterBuilders.rangeFilter("datefield").lte("now")
);
SearchSourceBuilder query = SearchSourceBuilder.searchSource().query(queryBuilder);
client.prepareMoreLikeThis("index","type","id")
.setField("field1","field2")
.setSearchSource(query)
.execute().actionGet();
So after strugling a little bit I found someone with the same problem. So his suggestion was to set the min_term_freq to 1.
So the code now looks like this:
FilteredQueryBuilder queryBuilder = new FilteredQueryBuilder(QueryBuilders.matchAllQuery(), FilterBuilders.rangeFilter("finish_date").lt("now"));
SearchSourceBuilder query = SearchSourceBuilder.searchSource().query(queryBuilder);
SearchResponse response = esClient.prepareMoreLikeThis("auction", "product", productId + "").setField("name.name", "description", "brand").setPercentTermsToMatch(0.3f)
.setMinTermFreq(1).setSearchSource(query).execute().actionGet();
But I dont know what this MinTermFreq does and if the value 1 is the right value. Someone know what is this field?
Thks for all the help!
Once again, Thank you for all the help and sorry for all the trouble!

IntelliJ IDEA code inspection: HQL custom dialect & registered functions

My question is about
using registered functions for date/time manipulations in Hibernate Query Language and
IntelliJ IDEA's code inspection for these registered functions in HQL.
I'm using Hibernate 4.2.5 with Java 7, and SQL Server 2008 R2 as the database, and IntelliJ IDEA 12.1.6.
In an HQL query I need to perform the TSQL DATEADD function - or the equivalent HQL date operation. This doesn't seem to exist.
Here's what I'd like to achieve:
update MyTable set startTime = GETDATE(), targetTime = DATEADD(HOUR, allocatedTime, GETDATE()), endTime = null where faultReport.faultReportId = :faultReportId and slaTypeId = :slaTypeId
Searching for answers online has been disappointingly no help, and the most common advice (like the comment seen here: https://stackoverflow.com/a/18150333/2753571) seems to be "don't use date manipulation in hql." I don't see how I can get around performing the operation in the SQL statement in the general case (e.g. when you want to update one column based on the value in another column in multiple rows).
In a similar fashion to the advice in this post: Date operations in HQL, I've subclassed a SQLServerDialect implementation and registered new functions:
registerFunction("get_date", new NoArgSQLFunction("GETDATE", StandardBasicTypes.TIMESTAMP)); // this function is a duplication of "current_timestamp" but is here for testing / illustration
registerFunction("add_hours", new VarArgsSQLFunction(TimestampType.INSTANCE, "DATEADD(HOUR,", ",", ")"));
and added this property to my persistence.xml:
<property name="hibernate.dialect" value="my.project.dialect.SqlServerDialectExtended" />
and then I'm testing with a simple (meaningless, admitted) query like this:
select x, get_date(), add_hours(1, get_date()) from MyTable x
The functions appear to be successfully registered, and that query seems to be working because the following SQL is generated and the results are correct:
select
faultrepor0_.FaultReportSLATrackingId as col_0_0_,
GETDATE() as col_1_0_,
DATEADD(HOUR,
1,
GETDATE()) as col_2_0_,
... etc.
But I now have this problem with IntelliJ IDEA: where get_date() is used in the HQL, the code inspection complains "<expression> expected, got ')'". This is marked as an error and the file is marked in red as a compilation failure.
Can someone can explain how to deal with this, please, or explain what a better approach is? Am I using the incorrect SQLFunction template (VarArgsSQLFunction)? If yes, which is the best one to use?
I'd like the usage of the registered function to not be marked as invalid in my IDE. Ideally, if someone can suggest a better way altogether than creating a new dialect subclass, that would be awesome.

OJB / Oracle XE sql debug-display problem

I have a Java application, and use OJB as my ORM technology. I have an Oracle XE installation locally to develop against. The problem is when I need to debug a problem, I like looking at the SQL output. Here is an example of SQL I can view through the "Top SQL" interface in Oracle XE:
select a_bunch_of_fields
from KREW_DOC_TYP_T A0
WHERE ((UPPER(A0.DOC_TYP_NM) LIKE :1) AND A0.ACTV_IND = :2) AND A0.CUR_IND = :3
The problem is I would like to see the real value instead of ":1". I can't seem to find how I can configure this. I know the real values are working, because the application is responding as expected, for the most part (hence the bugs I am working on).
Thanks,
Jay
One quick and dirty way is to look in the provided database views (v$sql_bind_capture and v$sqlarea). In the SQL below, I just added a like clause to match the sql statement you have above, you will then get a row for each bind variable and it's value. To target a very specific SQL statement you want the sql_id for your query.
SELECT a.sql_text, b.NAME, b.POSITION, b.datatype_string, b.value_string
FROM v$sql_bind_capture b, v$sqlarea b
WHERE b.sql_id = a.sql_id
and a.sql_text like '%UPPER(A0.DOC_TYP_NM) LIKE :1%'
Output (without the SQL the result would look look something like this):
"NAME","POSITION","DATATYPE_STRING","VALUE_STRING"
":B1","2","NUMBER","1001"

Categories

Resources