I do not know if I got it right but come on. I will assume that you already have a MySQL database running and that you will need to retrieve the last (highest) registration used and use it to determine the registration number of the new registration you are creating.
First of all, use a query to retrieve the values of the matrices and compare them to each other to find out which one is the largest.
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 this, call this method within your "persist" method or something and use the number returned +1 to determine the number of the new license plate.
Any questions, please comment here.