Ao executar:
agendamentoEmailDao.listarAgendamentosEmail()
org.h2.jdbc.JdbcSQLException: Table "AGENDAMENTOEMAIL" not found; SQL statement:
select agendament0_.id as id1_0_, agendament0_.assunto as assunto2_0_, agendament0_.email as email3_0_, agendament0_.enviado as enviado4_0_, agendament0_.mensagem as mensagem5_0
Ao executar :
salvarAgendamentoEmail()
07:28:42,934 ERROR [org.jboss.as.ejb3.invocation] (default task-2) WFLYEJB0034: EJB Invocation failed on component AgendamentoEmailBusiness for method public void br.com.alura.business.AgendamentoEmailBusiness.salvarAgendamentoEmail(br.com.alura.entity.AgendamentoEmail): javax.ejb.EJBTransactionRolledbackException: org.hibernate.PersistentObjectException: detached entity passed to persist: br.com.alura.entity.AgendamentoEmail
persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"
xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="agendamentoemail">
<class>com.alura.entity.AgendamentoEmail</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/agendamentobd" />
<property name="javax.persistence.jdbc.user" value="root" />
<property name="javax.persistence.jdbc.password" value="MINHA_SENHA)" />
</properties>
</persistence-unit>
</persistence>
Meu agendamentoEmailBusiness
package br.com.alura.business;
import java.util.List;
import javax.ejb.Stateless;
import javax.inject.Inject;
import br.com.alura.dao.AgendamentoEmailDao;
import br.com.alura.entity.AgendamentoEmail;
@Stateless
public class AgendamentoEmailBusiness {
@Inject
private AgendamentoEmailDao agendamentoEmailDao;
public List<AgendamentoEmail> listarAgendamentosEmail(){
return agendamentoEmailDao.listarAgendamentosEmail();
}
public void salvarAgendamentoEmail( AgendamentoEmail agendamentoEmail) {
agendamentoEmail.setEnviado(false);
agendamentoEmailDao.salvarAgendamentoEmail(agendamentoEmail);
}
}
Schema: agendamentobd
script:
create table AgendamentoEmail (id integer primary key auto_increment, email varchar(20), enviado boolean , assunto varchar(20), mensagem varchar(20));
insert into AgendamentoEmail (id, assunto, email, enviado, mensagem) values (3, 'teste','teste', 0, 'teste');