-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Add SQL query comments with JPA and Hibernate
PostPosted: Tue Apr 18, 2017 3:29 pm 
Newbie

Joined: Tue Apr 18, 2017 3:23 pm
Posts: 2
Hi,

is there a way to add a custom SQL comment to the generated SQL from Hibernate? For example, I would
like to add a SQL comment to SELECT statements that would eventually get executed by a Postgres
database.

Example:

/* t95=firstdraft */select foo, bar.....from ....

regards


Top
 Profile  
 
 Post subject: Re: add SQL comment to generated SQL
PostPosted: Tue Apr 18, 2017 11:56 pm 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1638
Location: Romania
If you are using the Hibernate native API, then you need to use the Query#setComment method like this:

Code:
List<Person> persons = (List<Person>) session.createQuery(
    "select p " +
    "from Person p ")
.setComment( "t95=firstdraft" )
.list();


If you are using JPA, then you can use a QueryHint:

Code:
List<Person> persons = entityManager.createQuery(
        "select p " +
        "from Person p ", Person.class)
.setHint( "org.hibernate.comment", "t95=firstdraft" )
.getResultList();


Top
 Profile  
 
 Post subject: Re: Add SQL query comments with JPA and Hibernate
PostPosted: Mon Apr 24, 2017 12:53 pm 
Newbie

Joined: Tue Apr 18, 2017 3:23 pm
Posts: 2
many thanks!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.