I'm having an error in JSF that I can not figure out. It looks like it's with my DAO product or Product. This was happening when I was recording a product, now the project does not even open.
Informações: visiting unvisited references
Informações: visiting unvisited references
Informações: visiting unvisited references
Informações: visiting unvisited references
Informações: visiting unvisited references
Grave: Exception while invoking class org.glassfish.persistence.jpa.JPADeployer prepare method
Grave: java.lang.RuntimeException: Invalid resource : { ResourceInfo : (jndiName=java:app/jdbc/loogix__pm), (applicationName=loogix) }
at com.sun.enterprise.connectors.ConnectorRuntime.lookupDataSourceInDAS(ConnectorRuntime.java:593)
at com.sun.enterprise.connectors.ConnectorRuntime.lookupPMResource(ConnectorRuntime.java:517)
at org.glassfish.persistence.common.PersistenceHelper.lookupPMResource(PersistenceHelper.java:63)
at org.glassfish.persistence.jpa.ProviderContainerContractInfoBase.lookupDataSource(ProviderContainerContractInfoBase.java:71)
at org.glassfish.persistence.jpa.PersistenceUnitInfoImpl.<init>(PersistenceUnitInfoImpl.java:108)
at org.glassfish.persistence.jpa.PersistenceUnitLoader.loadPU(PersistenceUnitLoader.java:142)
at org.glassfish.persistence.jpa.PersistenceUnitLoader.<init>(PersistenceUnitLoader.java:107)
at org.glassfish.persistence.jpa.JPADeployer$1.visitPUD(JPADeployer.java:223)
at org.glassfish.persistence.jpa.JPADeployer$PersistenceUnitDescriptorIterator.iteratePUDs(JPADeployer.java:510)
at org.glassfish.persistence.jpa.JPADeployer.createEMFs(JPADeployer.java:230)
at org.glassfish.persistence.jpa.JPADeployer.prepare(JPADeployer.java:168)
at com.sun.enterprise.v3.server.ApplicationLifecycle.prepareModule(ApplicationLifecycle.java:925)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:434)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:219)
at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:491)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:539)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:535)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:360)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2.execute(CommandRunnerImpl.java:534)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:565)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:557)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:360)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:556)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1464)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1300(CommandRunnerImpl.java:109)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1846)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1722)
at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:534)
at com.sun.enterprise.v3.admin.AdminAdapter.onMissingResource(AdminAdapter.java:224)
at org.glassfish.grizzly.http.server.StaticHttpHandlerBase.service(StaticHttpHandlerBase.java:189)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
at java.lang.Thread.run(Thread.java:748)
Caused by: com.sun.appserv.connectors.internal.api.ConnectorRuntimeException: Invalid resource : { ResourceInfo : (jndiName=java:app/jdbc/loogix__pm), (applicationName=loogix) }
at org.glassfish.jdbcruntime.service.JdbcDataSource.validateResource(JdbcDataSource.java:81)
at org.glassfish.jdbcruntime.service.JdbcDataSource.setResourceInfo(JdbcDataSource.java:62)
at org.glassfish.jdbcruntime.JdbcRuntimeExtension.lookupDataSourceInDAS(JdbcRuntimeExtension.java:136)
at com.sun.enterprise.connectors.ConnectorRuntime.lookupDataSourceInDAS(ConnectorRuntime.java:589)
Follow my classes that lead the way to writing a product.
Form that records a product:
<h:form>
<div class="message-box scroll">
<div class="message-in container-fluid p-l-3 p-r-3">
<div class="clearfix m-t-3">
<h:outputLabel for="codigo" value="Código" rendered="false"/>
<h:inputText value="#{produtoController.produto.codigo}" id="codigo" class="form-control" required="true" pt:placeholder="Digite o codigo do produto"/>
</div>
<div class="clearfix m-t-1">
<h:outputLabel for="nome" value="Nome:" rendered="false"/>
<h:inputText value="#{produtoController.produto.nome}" id="nome" class="form-control" required="true" pt:placeholder="Digite o nome do produto"/>
</div>
<div class="clearfix m-t-1">
<h:outputLabel for="descricao" value="Descrição" rendered="false"/>
<h:inputTextarea value="#{produtoController.produto.descricao}" id="descricao" class="form-control" required="true" pt:placeholder="Descrição do produto"/>
</div>
<div class="clearfix m-t-1">
<h:commandButton action="#{produtoController.gravar()}" value="Gravar produto" class="btn btn-success form-control" />
</div>
</div><!-- /.message-out -->
</div><!-- /.message-in -->
</h:form>
When I go to this page, I access an instance in my ProductController.java
public String novo() {
this.produto = new Produto();
this.alterando = false;
return "novo-produto?faces-redirect=true";
}
To burn, use:
public String gravar() {
if (this.alterando == false)
this.daoProduto.add(this.produto);
else
this.daoProduto.update(this.produto);
this.produtos = this.daoProduto.getList();
return "produto?faces-redirect=true";
}
My ProductDAO :
public class ProdutoDAO {
private GenericDAO<Produto> dao;
@PersistenceContext
private EntityManager em;
@PostConstruct
public void init() {
this.dao = new GenericDAO<Produto>(this.em);
}
public void add(Produto produto) {
this.dao.add(produto);
}
public void update(Produto produto) {
this.dao.update(produto);
}
public void delete(Produto produto) {
this.dao.delete(produto);
}
public List<Produto> getList() {
Query q = this.em.createQuery("select p from Produto p");
return q.getResultList();
}
}
I use a generic class because I can have thousands of DAO, and change the basics:
public class GenericDAO<T> {
private EntityManager em;
public GenericDAO(EntityManager em) {
this.em = em;
}
public void add(T t) {
this.em.persist(t);
}
public void update(T t) {
this.em.merge(t);
}
public void delete(T t) {
this.em.remove(t);
}
}
My class Product.java is as follows:
@Entity
public class Produto implements Serializable{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String codigo;
private String nome;
private String descricao;
@OneToMany(mappedBy = "produto")
private List<ProdutoAlmoxarifado> produtoAlmoxarifados;
public Produto() {
}
public void setCodigo(String codigo) {
this.codigo = codigo;
}
public String getCodigo() {
return codigo;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getDescricao() {
return descricao;
}
public void setDescricao(String descricao) {
this.descricao = descricao;
}
public List<ProdutoAlmoxarifado> getProdutos() {
return Collections.unmodifiableList(produtoAlmoxarifados);
}
public void addProdutoAlmoxarifado(ProdutoAlmoxarifado produtoAlmoxarifado) {
this.produtoAlmoxarifados.add(produtoAlmoxarifado);
produtoAlmoxarifado.setProduto(this);
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Override
public String toString() {
return "Produto{" + "id=" + id + ", codigo=" + codigo + ", nome=" + nome + ", descricao=" + descricao + '}';
}
@Override
public int hashCode() {
int hash = 3;
hash = 89 * hash + Objects.hashCode(this.id);
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Produto other = (Produto) obj;
if (!Objects.equals(this.id, other.id)) {
return false;
}
return true;
}
}
Can anyone help me find this error?