0

I have the next problem:

I am doing a project using JPA and Restfull whit netbeasn and postgres, I have the following persistence

<?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="PruebaPersitenciaPU" transaction-type="JTA">
    <jta-data-source>data_cotratacion</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties/>
  </persistence-unit>

And also the following code using the EntityManager:

@GET
    public String crearPersona(
            @QueryParam("id") String id,
            @QueryParam("name") String name,
            @QueryParam("gender") String gender,
            @QueryParam("date") String date){
        Persona p = new Persona();
        p.setId(id);
        p.setName(name);
        p.setGender(gender);
        p.setDate(stringToDate(date));
        try {        
            EntityManagerFactory emf = Persistence.createEntityManagerFactory("PruebaPersitenciaPU");
            EntityManager em = emf.createEntityManager();
            
            em.getTransaction().begin();
            em.persist(p);
            em.getTransaction().commit();
        
            return "Usuario Creado "+id;
        } catch (Exception e) {
            return "Usuario no creado error: "+e;
        }
    }

but try this sends me this error:

Usuario no creado error: javax.persistence.PersistenceException: Exception [EclipseLink-7060] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.ValidationException Exception Description: Cannot acquire data source [data_cotratacion]. Internal Exception: javax.naming.NamingException: Lookup failed for 'data_cotratacion' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: data_cotratacion not found]

1 Answers1

0

Sounds like there is no JDBC datasource configured with the name data_cotratacion. You need to configure this JDBC resource on your application server.

Or you need to create your persistence unit by using the wizard in netbeans go in the menu to File > New File Then select Persistence in the left box and Persistence Unit in the right box.

Eelke
  • 20,897
  • 4
  • 50
  • 76