I’m not sure I understand, but come on. I will assume that you already have a running Mysql database and that you will need to recover the last (highest) enrollment used and use it to determine which registration number of the new registration you are creating.
First of all, use a query to retrieve the values of the registrations and compare them to each other to find out which is the biggest.
private int getUltimaMatricula() {
EntityManager em = createEntityManagerFactory();
em.getTransaction().begin();
Query q = em.createQuery("SELECT t.coluna1 from tabela t where t.campo1 = :campo1");
// campo1 e o que voce ira utilizar para recuperar as matriculas, utilizando jpql
// neste caso.
q.setParameter("campo1", campo1);
List<Integer> result = q.getResultList();
int maiorNumero = Integer.MIN_VALUE;
for(i=0; i<result.size(); i++){
if (result.get(i) > maiorNumero)
maiorNumero = result.get(i);
}
em.getTransaction().commit();
em.close();
return maiorValor;
}
After that, call this method inside your "persist" method or something of the type and use the number returned +1 to determine the number of the new enrollment.
Any questions, comment here.
Did you mean
Obrigado pela ajuda!
orDe nada pela ajuda!
? rs.. Because apparently you solved the problem of the author of the question, or am I mistaken?– Math
It was "Thanks for the help" even, rsrs, because I am the author of the question, but when I asked, was not yet registered. I asked as a guest, so the name is different. I posted the solution to help in case someone needs.
– DGB
You can merge your accounts by contacting us at: http://answall.com/contact so you can regain authorship of the question and accept the answer that helped you most, if you consider it so.
– Math