facebook

JPA + MyEclipse Reverse Engineer + findByProperty

  1. MyEclipse Archived
  2.  > 
  3. Database Tools (DB Explorer, Hibernate, etc.)
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #302986 Reply

    logixplayer
    Member

    Hi I am using myEclipse and have reverse generated a DAO class.
    One of the methods is:

    public List<Submission> findByProperty(String propertyName,
    final Object value, final int… rowStartIdxAndCount)

    In my case, a Topic contains many Submissions. A topic is the parent of many submissions. One to many relationship. here is how I am getting my submissions:

    List<Submission> submissions = submissionService.findByProperty(“topic”, topic, null);

    This however gives me the ALL the Submission rows starting from the first record inserted. What if I want the order reversed? So I want to ORDER DESC? Order Descending, and then retrieve the records?? In other words, in my case, the records at the end are the latest most recent records.
    Essentially, I can actually reverse this based on my “date” column in my Submission table. Order by date and then make it descending.

    Is there any way I can achieve this with the reverse generated logic without using native sql for example???

    #302990 Reply

    logixplayer,
    I am afraid, you cannot do that while reverse engineering. You should make changes to your query in DAO or manipulate the final list you obtain. It is preferable to manipulate the list.

    #303003 Reply

    logixplayer
    Member

    @support-shalini wrote:

    logixplayer,
    I am afraid, you cannot do that while reverse engineering. You should make changes to your query in DAO or manipulate the final list you obtain. It is preferable to manipulate the list.

    Ok here is a scenario. Let’s say I have 5000 records and I only want 4950 to 5000. How can I manipulate the list? Do I have to get ALL records and then take the last few? This will be highly in-efficient.

    Can you suggest a way where I can manipulate the list or the query in the best way?
    This is what I am doing right now, manually writing the query:

    “SELECT * FROM Submission s WHERE s.topicID=?1 ORDER BY s.date DESC LIMIT 0,50 ;”;

    I would rather just use the reverse generate code. Any suggestions? Please advise.

    #303046 Reply

    logixplayer,
    To manipulate the query, you can use query.setMaxResults(2).
    This will limit the number of results returned in the list.

    #303079 Reply

    logixplayer
    Member

    @support-shalini wrote:

    logixplayer,
    To manipulate the query, you can use query.setMaxResults(2).
    This will limit the number of results returned in the list.

    How does query.setMaxResults(2). reverse the order and ORDER by date?
    Nonetheless, even if not ordered by date, I still want the final x records,
    query.setMaxResults(2). [2? I think you mean x, where x is an arbitrary number]
    will only give me the first X records….

    So I still don’t understand how to reverse the results and get those X records?
    Please advise.
    Thank you.

    #303092 Reply

    logixplayer,
    query.setMaxResults(x) does not reverse the order, you should use “desc” in the query.
    To limit the number of results in the list you can give an integer value for “x”.

Viewing 6 posts - 1 through 6 (of 6 total)
Reply To: JPA + MyEclipse Reverse Engineer + findByProperty

You must be logged in to post in the forum log in