Galera, tou com o seguinte pôbréma: tenho uma classe aluno:
@Entity
@Table(name = "aluno")
@NamedQueries({@NamedQuery(name = "Aluno.findAll", query = "SELECT a FROM Aluno a"), @NamedQuery(name = "Aluno.findByCodAluno", query = "SELECT a FROM Aluno a WHERE a.codAluno = :codAluno"), @NamedQuery(name = "Aluno.findByNomAluno", query = "SELECT a FROM Aluno a WHERE a.nomAluno = :nomAluno"), @NamedQuery(name = "Aluno.findByDatNascimento", query = "SELECT a FROM Aluno a WHERE a.datNascimento = :datNascimento"), @NamedQuery(name = "Aluno.findBySexAluno", query = "SELECT a FROM Aluno a WHERE a.sexAluno = :sexAluno"), @NamedQuery(name = "Aluno.findByEndRuaAv", query = "SELECT a FROM Aluno a WHERE a.endRuaAv = :endRuaAv"), @NamedQuery(name = "Aluno.findByEndNumero", query = "SELECT a FROM Aluno a WHERE a.endNumero = :endNumero"), @NamedQuery(name = "Aluno.findByEndBairro", query = "SELECT a FROM Aluno a WHERE a.endBairro = :endBairro"), @NamedQuery(name = "Aluno.findByEndComplemento", query = "SELECT a FROM Aluno a WHERE a.endComplemento = :endComplemento"), @NamedQuery(name = "Aluno.findByEndCidade", query = "SELECT a FROM Aluno a WHERE a.endCidade = :endCidade"), @NamedQuery(name = "Aluno.findByEndUF", query = "SELECT a FROM Aluno a WHERE a.endUF = :endUF"), @NamedQuery(name = "Aluno.findByEndCEP", query = "SELECT a FROM Aluno a WHERE a.endCEP = :endCEP"), @NamedQuery(name = "Aluno.findByTelFixo", query = "SELECT a FROM Aluno a WHERE a.telFixo = :telFixo"), @NamedQuery(name = "Aluno.findByTelCelular", query = "SELECT a FROM Aluno a WHERE a.telCelular = :telCelular"), @NamedQuery(name = "Aluno.findByDatIngresso", query = "SELECT a FROM Aluno a WHERE a.datIngresso = :datIngresso"), @NamedQuery(name = "Aluno.findByCatSocio", query = "SELECT a FROM Aluno a WHERE a.catSocio = :catSocio"), @NamedQuery(name = "Aluno.findByDatVencimento", query = "SELECT a FROM Aluno a WHERE a.datVencimento = :datVencimento"), @NamedQuery(name = "Aluno.findByVlrPagar", query = "SELECT a FROM Aluno a WHERE a.vlrPagar = :vlrPagar"), @NamedQuery(name = "Aluno.findByFlgFrequencia", query = "SELECT a FROM Aluno a WHERE a.flgFrequencia = :flgFrequencia")})
public class Aluno implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "cod_Aluno")
private Integer codAluno;
@Basic(optional = false)
@Column(name = "nom_Aluno")
private String nomAluno;
...
e persisto Aluno da seguinte forma:
...
em.getTransaction().begin();
try {
em.persist(this);
em.getTransaction().commit();
} catch (Exception e) {
e.printStackTrace();
em.getTransaction().rollback();
} finally {
em.close();
}
...
Vejam o erro que está dando:
java.lang.IllegalArgumentException: Object: obj.Aluno[codAluno=null] is not a known entity type.
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.registerNewObjectForPersist(UnitOfWorkImpl.java:3820)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.persist(EntityManagerImpl.java:219)
at interfeceacademiareal.Aluno.AlunoForm.salvarAluno(AlunoForm.java:31)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at net.java.dev.genesis.reflection.ReflectionInvoker.invoke(ReflectionInvoker.java:45)
at net.java.dev.genesis.ui.metadata.MethodMetadata.invoke(MethodMetadata.java:70)
at net.java.dev.genesis.ui.controller.DefaultFormController.invokeAction(DefaultFormController.java:597)
at net.java.dev.genesis.ui.controller.DefaultFormController.invokeActionWithReset(DefaultFormController.java:809)
at net.java.dev.genesis.ui.controller.DefaultFormController.invokeAction(DefaultFormController.java:798)
at net.java.dev.genesis.ui.binding.AbstractBinder.invokeAction(AbstractBinder.java:587)
at net.java.dev.genesis.ui.binding.AbstractBinder.invokeFormAction(AbstractBinder.java:781)
at net.java.dev.genesis.ui.swing.components.AbstractComponentBinder$ComponentBoundAction$1.actionPerformed(AbstractComponentBinder.java:353)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6263)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6028)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2475)
at java.awt.Component.dispatchEvent(Component.java:4460)
Na minha tabela, o campo cod_Aluno está como Auto Increment. Parece que, por algum motivo, o JPA está mandando NULL para o campo auto increment. Sei lá, Alguém tem alguma idéia???