6

I have JPQL/Hibernate for DA layer. I have a table as following:

CREATE TABLE Log_Tbl
(
id number,
name varchar2(30),
);

and I have a entity for above table as following:

@Entity
@Table(name = "Log_Tbl")
public class ELog
{
  @Column(name = "id")
  private long entity_id;

  @Column(name = "name") 
  private String entity_name;
}

and map Log entity to Log_Tbl table by jpa; I have two JPQL queries as following:

  • select ELog from ELog where entity_name = 'Job'
  • select ELog from ELog where name = 'Job'

Both queries returned the correct result. My question is:

Why does the second query return the correct result although I used the column name instead of the entity_name property?

4
  • second is illegal JPQL and non-portable. Commented Dec 7, 2014 at 17:33
  • @NeilStockton but second query executed and answered fine also Commented Dec 7, 2014 at 17:37
  • and as I said, it is invalid JPQL, and if it works in your JPA implementation then you can't rely on it in ANY other Commented Dec 7, 2014 at 17:49
  • @NeilStockton I means is your answer, really it is dependent to JPA implementation? (in my situation its Hibernate) Commented Dec 7, 2014 at 18:33

1 Answer 1

4

To quote a post to a similar (if not duplicate) question

When you use something that isn't known by Hibernate in the WHERE clause of an HQL query (e.g. a function that is not registered in the SQL dialect), Hibernate acts smartly and passes it directly to the database.

So, it does work but it is vendor specific and probably wouldn't work if you switched your JPA implementation.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, My goal is ensure that it is vendor specific and maybe not worked on another JPA implementations.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.