0
I’m doing a criminal record project. The goal is to register and consult customers and employees, however, it is already possible to save the data, the problem is to consult. I made Jpanel forms (I am using netbeans), where to query you must fill in the Name and Email field for both forms and then just click the Refer button.
The code I entered in the query button is as follows::
ClienteControle cc = new ClienteControle();
try {
List<Cliente> ListaDeClientes = cc.buscar(txbNome.getText(),
txbEmail.getText());
DefaultTableModel model =
(DefaultTableModel) tbResultados.getModel();
for (int i = model.getRowCount() - 1; i >= 0; i--) {
model.removeRow(i);
}
if (ListaDeClientes != null) {
for (int i = 0; i < ListaDeClientes.size(); i++) {
Cliente cliente = ListaDeClientes.get(i);
String[] c = new String[]{
cliente.getNome(),
cliente.getEmail()};
model.insertRow(i, c);
}
}
tbResultados.setModel(model);
} catch (Exception e) {
JOptionPane.showMessageDialog(this,
"Não foi possível realizar a consulta de clientes!\n\n"
+ e.getLocalizedMessage());
}
In the above code I entered the Clientecontrol class which has the following method:
public List<Cliente> buscar(String nome, String email)
throws Exception {
return null;
}
Then I created the following method within the Customer class so that I could consult before the connection to the database:
public List<Cliente> getListaDeClientes(String nome, String email)
throws Exception {
EntityManager em = getEntityManager();
try {
String hql ="";
if(nome != null && !nome.equals("")) {
hql += " WHERE nome like upper (:nome)";
}
if (email != null && !email.equals("")) {
if (!hql.equals("")) {
hql += " AND email like lower(:email)";
} else {
hql += " WHERE email like lower(:email)";
}
}
hql = "FROM Cliente" + hql;
Query q = em.createQuery(hql);
if(nome != null && !nome.equals("")) {
q.setParameter("nome", "%" +
nome.toLowerCase() + "&");
}
if (email != null & !email.equals("")) {
q.setParameter("email", "%" +
email.toLowerCase() + "%");
}
return q.getResultList();
} finally {
em.close();
}
}
And then I changed the search method from Clientecontrol to:
public List<Cliente> buscar(String nome, String email)
throws Exception {
return new ClienteDAO().getListaDeClientes(nome, email);
}
The button should run normally but appears these error messages:
Exception Description: An Exception was thrown while Searching for pesistence Archives with Classloader: sun.misc.Launcher$Appclassloader@5c647e05
Internal Exception: javax.persistence.Persistenceexception: Exception [Eclipselink-28018](Eclipse Persistense Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.Entitymanagersetupexception
Exception Exception Description: Predeployment of Persistenceunit[Cadastropu] failed.org.eclipse.persistence.exceptions.Validationexception
Internal Exception: Exception [Eclipselink-7299](Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd)
Exception Description: Conflicting Annotations with the same name [SEQ_STORE] Were found. the first one [@javax.persistence.Sequencegenerator({allocationSize=20, name=SEQ_STORE, sequenceName= funcio_seq})] was found Within [class cadastro.Pessoa.Funcionario] and the Second [@javax.persistence.Sequencegenerator({allocationSize=20, name=SEQ_STORE, sequenceName=cliente_seq})] was found Within [class Customer]. Named Annotations must be Unique Across the persistence Unit.
Why does this come up? There’s a way to fix it?
According to that mistake:
Exception Description: Conflicting annotations with the same name [SEQ_STORE] were found. the first one [@javax.persistence.SequenceGenerator({allocationSize=20, name=SEQ_STORE, sequenceName= funcionario_seq})] was found within [class cadastro.Pessoa.Funcionario] and the second [@javax.persistence.SequenceGenerator({allocationSize=20, name=SEQ_STORE, sequenceName=cliente_seq})] was found within [class cadastro.Pessoa.Cliente]. Named annotations..
Annotations conflicts. put your Client and Employee class or try to change the attributename
of@SequenceGenerator
.– Viktor Hugo