Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9152063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:57:08+00:00 2026-06-17T11:57:08+00:00

I have below table in my MS SQL 2008 MyTable ———————- ID int (identity),

  • 0

I have below table in my MS SQL 2008

MyTable

----------------------
ID int (identity), 
action varchar(20),
uri int,
pid int,
url varchar(20),
lastpubdate date,
flag varchar(20)

And below are few sample records from the table:

ID      action      uri     pid     url                 lastpubdate         flag
---------------------------------------------------------------------------------
1       ADD         123     233     /en/index.aspx      15 JAN 2013:09:44   NULL
2       UPD         123     233     /en/index.aspx      15 JAN 2013:10:00   NULL
3       UPD         123     233     /en/index.aspx      15 JAN 2013:10:15   NULL
4       DEL         123     233     /en/index.aspx      15 JAN 2013:10:17   NULL

Now I want to write method which will return one record back using hibernate query on the basis of above table on the basis of uri and pid given to method, so it goes as below:

public MyTable findByLastPubDate(String uri,int pid)
{
    log.info("Entering Method: MyTable.findByLastPubDate");
    StringBuilder queryBuilder = new StringBuilder();
    queryBuilder.append("select top 1 from MyTable pa where pa.publication_id = :pid and  pa.uri = :uri and pa.flag IS NULL order by pa.last_published_date DESC");

    Map<String, Object> queryParams = new HashMap<String, Object>();
    queryParams.put("publication_id", pid);
    queryParams.put("tcmUri", uri);

    log.debug("findByLastPubDate -> queryBuilder- "+ queryBuilder.toString());        
    return executeQuerySingleResult(queryBuilder.toString(), queryParams);
}

Please suggest whether above method is correct or need some modifications

Edit:
I want to implement below query in Hibernate

SELECT 
 pa.[ID]
      ,pa.[ACTION]
      ,pa.[PUBLICATION_ID]
      ,pa.[ITEM_REFERENCE_ID]
      ,pa.[ITEM_TYPE]
      ,pa.[LAST_PUBLISHED_DATE]
      ,pa.[URL]
      ,pa.[SCHEMA_ID]
      ,pa.[flag]
FROM [mytable] a
WHERE pa.ID IN
(SELECT TOP 1 b.id FROM [mytable] b WHERE b.[ITEM_REFERENCE_ID] = 342349 and
b.[PUBLICATION_ID] = 233
ORDER BY b.[LAST_PUBLISHED_DATE] DESC)

Modified Method:

public PublishAction findbyLatestPublishedDate(int tcmURI,int pubID) throws StorageException
    {
        log.info("Entering Method: JPAPublishActionDAO.PublishAction.findbyLatestPublishedDate");
        StringBuilder queryBuilder = new StringBuilder();
        queryBuilder.append("select pa from PublishAction pa where pa.id in(select pb.id from PublishAction pb where pb.tcmUri = :tcmURI and pb.publication_id = :pubID and rownum <= 1 order by pb.last_published_date desc)");

        Map<String, Object> queryParams = new HashMap<String, Object>();
        queryParams.put("publication_id", pubID);
        queryParams.put("tcmUri", tcmURI);

        log.debug("JPAPublishActionDAO findbyLatestPublishedDate -> queryBuilder- "+ queryBuilder.toString());        
        return executeQuerySingleResult(queryBuilder.toString(), queryParams);
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T11:57:10+00:00Added an answer on June 17, 2026 at 11:57 am

    I am not sure about your table structure, however you would need to make double call to database.

    public PublishAction getLatestRecordonBasedID(int tcmURI,int pubID) throws StorageException
    {
        StringBuilder queryBuilder = new StringBuilder();
        queryBuilder.append("from PublishAction pb where pb.ITEM_REFERENCE_ID = :tcmURI and pb.PUBLICATION_ID = :pubID order by pb.LAST_PUBLISHED_DATE desc");
    
        Map<String, Object> queryParams = new HashMap<String, Object>();   
        queryParams.put("tcmURI", tcmURI);
        queryParams.put("pubID", pubID);
    
        final List<PublishAction> myActions = executeQueryListResult(queryBuilder.toString(), queryParams, 1);
    
        if (myActions != null && !myActions.isEmpty()) 
        {
            StringBuilder queryBuilderFinal = new StringBuilder();
            queryBuilderFinal.append("select pa from PublishAction pa where pa.id=:myId");
    
            Map<String, Object> queryParamsFinal = new HashMap<String, Object>();   
            queryParamsFinal.put("myId", myActions.get(0).getId()); 
            return executeQuerySingleResult(queryBuilderFinal.toString(), queryParamsFinal);
        }
        else 
        {
            return null;
        }
    }
    

    You can try something like above got solution after googling little.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have four tables like below in sql server 2008 : TABLE 1 ->
I have a Money column in my SQL Server 2008 table. In my below
I have an SQL table defined as below: CREATE TABLE [TestComposite] ( ID int,
I have below table in SQL server 2008.Please help to get expected output Thanks.
In SQL Server 2008, I have below Table Sample. Name Num ---------- John 20
In SQL server 2008, I have below table Score. I want to show Score1
I am using SQL Server 2008. I have a table like below: ID Name
I'm using SQL Server 2008. Let's say I have two hypothetical tables like below:
I have a table similar to below in sql server 2005 date_column | field1
I have a T-SQL query as below which queries a table holding the search

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.