Combine between and like in Spring Data JPA - spring

I want to create query to find all rows in a PostgreSQL table where a column value is between a pair of dates and another column value is like a keyword using Spring Data JPA.
Need to find records in table mapped to entity Student where dob is between from and to and name like keyword

Here's the HQL:
from Student s where s.name like :keyword and s.dob between :from and :to
:keyword, :from and :to are parameters of the query

Related

Nifi throwing None of the fields in the record map to the columns defined by [table name]

Am trying execute a sql query on oracle database and inserting the result into another table, for my trial am just performing a simple query as
SELECT 1 AS count
FROM dual
and trying to insert that into a single column table which has the name COUNT.
The content of the record on Nifi seems to be as follows
[
{
"COUNT" : "1"
}
]
but the logs keeps throwing the error
due to java.sql.SQLDataException:
None of the fields in the record map to the columns defined by
the schema_name.table_name table:
any ideas ?
I believe you get that same error message if your table name doesn't match. The Translate Field Names property only translates the fields (columns), not the table name. Try specifying the schema/table in uppercase to match what Oracle is expecting.

Querying a ManytoOne Relationship using #Query in Spring Data

I have Employees table which has many-to-one relationship to Company table ( similar to my situation). I am currently using Spring Data Repositories.
Now I am a bit confused on how to get employees matching join-date and Employer Id . As it is a many to one relation, Employees Entity has a Employer Entity with the mapping.
I thought of using #Query Annotation with a query like below:
#Query(Select emp from Employee emp where emp.joindate= ?1 and emp.employer.id =?2)
Employees methodname ( arg1, arg2)
Any Corrections or Suggestions ? . I don’t see good documentation on #Query. Please post if u have gone thru one

Auto Generated Id Using Fluent NHibernate with Oracle 11g

I am having issues inserting records using Fluent NHibernate. The code is trying to get a number from a sequence that is non-existent for the KEY field.
{"could not insert: [Class Name ][SQL: INSERT INTO Schema.TableName (KEY, ID) VALUES (hibernate_sequence.nextval, ?) returning KEY into :nhIdOutParam]"}
Of course the hibernate_sequence sequence doesn’t exist in the database. If I do an insert using SQL Developer say:
INSERT INTO Schema.TableName (ID) VALUES (90); this works and my primary key (KEY) is auto-generated.
I know you can use a sequence to auto generate this value using GenerateBY.Sequence() but is there a way to insert the record using the SQL statment about using Fluent Nhibernate?
I have my class mapped to the primary key in my class for ex.
Id(x => x.Id, "KEY");
Use this. It will insert all of the fields except for the Id which will let Oracle set it for you.
Id(x => x.Id, "KEY").GeneratedBy.Increment();

Oracle query Java EE, Entity Manager

If I have an Oracle database, with structure, SCHEMA/TABLE1 SCHEMA/TABLE2 and I want to create a query to select all rows from Table1, would it be,
"Select x from SCHEMA.TABLE1 x"
If you have an entity such as:
#Entity
#Table(schema="SCHEMA", name="TABLE1")
public class Table1Class {
...
}
Then, the following basic JPQL Query would select all the Table1Class entities:
Select x from Table1Class x.
Summing up, you don't need to (not that you can, either) specify schema and table name on JPQL queries, just the class name the table is mapped to.

how to write parameter string for include for linq query?

If table Employee has foreign key for table person, department,
when get the entity of employee, I want to both associated entities loaded too.
how to write the linq query? like below?
var employee = this.Context.Employee.Include("Person, Department");
It seems not working.
var employee = this.Context.Employee.Include("Person").Include("Department");

Resources