users@glassfish.java.net

Switching from 03.01 to 3.1 glassfish - null entity when the entity comes in

From: <forums_at_java.net>
Date: Fri, 8 Jul 2011 17:00:12 -0500 (CDT)

javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse
Persistence Services - 2.2.0.v20110202-r8913):
org.eclipse.persistence.exceptions.DatabaseException
Internal Exception:
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException:
Column 'Descripcion' cannot be null

The exception is understandable because the entity is null when comes in the
ejb.

This code work fine in the version 3.01 but in the version 3.1 not
work.(Object entity null when comes in the ejb)

package com.ejbs;
/**
 * The persistent class for the anio database table.
 *
 */

import java.io.Serializable;
import javax.persistence.*;
@Entity
@Table(name="anio")
public class Anio implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @SequenceGenerator(name="ANIO_PK_ANIO_GENERATOR" )
    @GeneratedValue(strategy=GenerationType.SEQUENCE,
generator="ANIO_PK_ANIO_GENERATOR")
    @Column(name="Pk_Anio", unique=true, nullable=false)
    private int pk_Anio;
    @Column(name="Descripcion", nullable=false, length=50)
    private String descripcion;
    public Anio() {
    }
    public int getPk_Anio() {
        return this.pk_Anio;
    }
    public void setPk_Anio(int pk_Anio) {
        this.pk_Anio = pk_Anio;
    }
    public String getDescripcion() {
        return this.descripcion;
    }
    public void setDescripcion(String descripcion) {
        this.descripcion = descripcion;
    }
}

package com.vista.formularios;
/**
 * The Aplication client.
 *
 */
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import com.ejbs.Anio;
import com.ejbs.AnioBean;
import com.ejbs.AnioBeanRemoto;
public class ApliClient {
    private Anio anio;  //  @jve:decl-index=0:
    private AnioBeanRemoto beanAnio;
    public ApliClient() {
        super();
        try {
            System.setProperty("org.omg.CORBA.ORBInitialHost",
"192.168.0.10");
            Context context = new InitialContext();
            beanAnio = (AnioBeanRemoto)
context.lookup(AnioBean.RemoteJNDIName);
            try {
                anio = new Anio();
                anio.setDescripcion("Test");
                //here i send the object anio to the ejb (in this
point the column descripcion got the valor "Test")
                beanAnio.crearAnio(anio);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        } catch (NamingException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }
}

package com.ejbs;
/**
 * The Stateless Session Beans
 *
 */
import javax.ejb.*;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import com.ejbs.Anio;
@Stateless
public class AnioBean implements AnioBeanRemoto {
    @PersistenceContext(unitName="EjbProyect")
    EntityManager em;
   
    public static final String RemoteJNDIName =
"java:global/Ear/Ejb/AnioBean!com.beans.AnioBeanRemoto";
    public void crearAnio(Anio anio) throws Exception {
        try {
            //here the ejb receives the object "anio" from the
client but here the column anio.descripcion is Null
            em.persist(anio);
            em.flush();
        } catch(Exception ex) {
            throw new Exception(ex.toString());
        }
    }
}

package com.ejbs;
/**
 * The Interface
 *
 */
import javax.ejb.*;
import com.ejbs.Anio;
@Remote
public interface AnioBeanRemoto {
    public void crearAnio(Anio anio) throws Exception;
}

Is very strange than a one version to another of glassfish not working.

I use EJB 3.1 and JPA 2.0. - Eclipse Helios 3.6


--
[Message sent by forum member 'charlie2610']
View Post: http://forums.java.net/node/820363