java - Convert PostgreSQL Query into corresponding Hibernate Query -


i need corresponding hibernate query postgresql query.

here query

select date(row_created) demotable 

where date inbuilt function in postgresql , row_created column in demotable having data type of timestamp without time zone.

here pojo class

import java.util.arraylist; import java.util.date; import java.util.list; import javax.persistence.cascadetype; import javax.persistence.column; import javax.persistence.entity; import javax.persistence.generatedvalue; import javax.persistence.generationtype; import javax.persistence.id; import javax.persistence.joincolumn; import javax.persistence.manytoone; import javax.persistence.onetomany; import javax.persistence.table; import javax.persistence.transient; import javax.validation.constraints.notnull; @entity @table(name = "candidate") public class candidates {      @id     @column(name = "id")     @generatedvalue(strategy = generationtype.auto)     private int candidateid;      @notnull     @column(name = "name")     private string name;      @notnull     @column(name = "mail_id")     private string mailid;      @notnull     @column(name = "mobile_number")     private string mobilenumber;      @column(name = "experience")     private string experience;      @column(name = "ctc")     private string ctc;      @column(name = "company")     private string company;      @notnull     @column(name = "notice_period")     private string noticeperiod;      @column(name = "prefered_job_location")     private string preferedjoblocation;      @column(name = "resume_filepath_name")     private string resumefilepathname;      @column(name = "primary_skill")     private string primaryskill;      @notnull     @column(name = "is_active")     private short isactive;      @notnull     @column(name = "row_created")     private date rowcreated;      @column(name = "row_altered")     private date rowaltered;      @notnull     @manytoone     @joincolumn(name="tracker_fk_id")     private tracker trackerfk;  } 

can equivalent hibernate query that.

thanks

you can create query this:

//select object want query query = em.createnamedquery("select demotable mycondition"); 

1-in case single date

//get result list or single result want demotableentity myresult = (demotableentity) query.getsingleresult();  //get date result date mydate = myresult.getrowcreated(); 

2-in case liste of date

list<date> listedate = new arraylist<>();  list<demotableentity> list = query.getresultlist();  for(demotableentity ent : list){    listedate.add(ent.getrowcreated()); } 

3-in case list of result of 1 column

query query = em.createnamedquery("select a.rowaltered candidates a"); list<date> dates = query.getresultlist(); 

hope can you.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -