hql - Setting the sortorder using hibernate -


I am working on Spring-MVC I am using Hibernate as an ORM tool. The table in which there is a column called 'note order', so for any CRUED operation, the order of data in the database is managed by the note order.

Question: After any CRUD operation, I want to start the Notarder with 1 and I want to increase it till the end of the table.

How do I use hibernate queries I did something similar, find any I am posting the code below for reference. I function returns a list.

  @ Override public list & lt; Notes & gt; ListNotesBySectionId (Int Sected, Individual) {int personid = person.getId (); If (session == zero) {session = this.sessionFactory.openSession (); } And {session = this.sessionFactory.getCurrentSession (); } Query query = session.createQuery ("n.person1.id =: id and n.sectionid =: n.noteorder by sectionid order"); Query.setParameter ("id", personid); Query.setParameter ("sectionid", sectionid); & Lt; Notes & gt; Notes list = query.list (); // This list is nodelist by asking .getNoteOrder (); System.out.println ("Per-Notes Per Person Notes" + notes list); Return notes list; }  

You can do this with the @order column annotation For example, entry for example;

  @EntiType public class person applies serializable (personal static last long serial VERSIONUID = 1L; @ id @ column (name = "id") private id id; @column (name = " Name ") private string name; @OneToMany (cascade = CascadeType.ALL) @order column (name =" notender ") private list & lt; notes & gt; comments; ...  

From the documentation about the order column,

specifies a column that can be used to maintain the continuous order of the list. In this case @OrderColumn

/ Code> will create columns in your notes table with the name noter , and there will be the same index as it is in the list of notes, so each restart will Notarder will affect your query should now work.

Hope this is helpful Received.


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -