import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
/**
*
* @author Francisco
*/
@Entity
@Table(name = "USUARIO")
public class Usuario implements Serializable, Comparable<Usuario> {
private int codigo = 0;
public static final String PROP_CODIGO = "codigo";
private String nome = "";
public static final String PROP_NOME = "nome";
private String senha;
public static final String PROP_SENHA = "senha";
private int nivel = 0;
public static final String PROP_NIVEL = "nivel";
private boolean logado = false;
public static final String PROP_LOGADO = "logado";
private Date dataUltimoAcesso;
public static final String PROP_DATAULTIMOACESSO = "dataUltimoAcesso";
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "DATA_ULTIMO_ACESSO")
public Date getDataUltimoAcesso() {
return dataUltimoAcesso;
}
public void setDataUltimoAcesso(Date dataUltimoAcesso) {
Date oldDataUltimoAcesso = this.dataUltimoAcesso;
this.dataUltimoAcesso = dataUltimoAcesso;
propertyChangeSupport.firePropertyChange(PROP_DATAULTIMOACESSO, oldDataUltimoAcesso, dataUltimoAcesso);
}
@Column(name = "LOGADO")
public boolean isLogado() {
return logado;
}
public void setLogado(boolean logado) {
boolean oldLogado = this.logado;
this.logado = logado;
propertyChangeSupport.firePropertyChange(PROP_LOGADO, oldLogado, logado);
}
@Column(name = "NIVEL")
public int getNivel() {
return nivel;
}
public void setNivel(int nivel) {
int oldNivel = this.nivel;
this.nivel = nivel;
propertyChangeSupport.firePropertyChange(PROP_NIVEL, oldNivel, nivel);
}
@Column(name = "SENHA")
public String getSenha() {
return senha;
}
public void setSenha(String senha) {
String oldSenha = this.senha;
this.senha = senha;
propertyChangeSupport.firePropertyChange(PROP_SENHA, oldSenha, senha);
}
@Column(name = "NOME_REAL")
public String getNome() {
return nome;
}
public void setNome(String nome) {
String oldNome = this.nome;
this.nome = nome;
propertyChangeSupport.firePropertyChange(PROP_NOME, oldNome, nome);
}
@Id
@Column(name = "CODIGO")
public int getCodigo() {
return codigo;
}
public void setCodigo(int codigo) {
int oldCodigo = this.codigo;
this.codigo = codigo;
propertyChangeSupport.firePropertyChange(PROP_CODIGO, oldCodigo, codigo);
}
private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
public void addPropertyChangeListener(PropertyChangeListener listener) {
propertyChangeSupport.addPropertyChangeListener(listener);
}
public void removePropertyChangeListener(PropertyChangeListener listener) {
propertyChangeSupport.removePropertyChangeListener(listener);
}
public Usuario() {
}
@Override
public int hashCode() {
int ret = 0;
if (this.getCodigo() > 0) {
ret = (this.getCodigo() * 123);
}
return ret;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Usuario other = (Usuario) obj;
if (this.codigo != other.getCodigo()) {
return false;
}
return true;
}
public int compareTo(Usuario o) {
if (this.hashCode() < o.hashCode()) {
return -1;
} else if (this.hashCode() == o.hashCode()) {
return 0;
} else if (this.hashCode() > o.hashCode()) {
return 1;
} else {
return 1;
}
}
@Override
public String toString() {
return this.getNome();
}
}
// Create EntityManagerFactory for persistent unit named "pu1"
// to be used in this test
emf = Persistence.createEntityManagerFactory("HorusPU");
// Persist all entities
createTransactionalEntityManager();
//System.out.println("Inserting Customer and Orders... " + testInsert());
// Create new customer
Usuario item = new Usuario();
item.setCodigo(10);
item.setNome("FRANCISCO VIEIRA");
item.setLogado(false);
// Persist the customer
em.persist(item);
closeTransactionalEntityManager();
[TopLink Info]: 2009.11.25 02:42:46.921--ServerSession(12893236)--TopLink, version: Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))
[TopLink Info]: 2009.11.25 02:42:47.656--Not able to detect platform for vendor name [Firebird]. Defaulting to [oracle.toplink.essentials.platform.database.DatabasePlatform]. The database dialect used may not match with the database you are using. Please explicitly provide a platform using property toplink.platform.class.name.
[TopLink Info]: 2009.11.25 02:42:48.140--ServerSession(12893236)--file:/C:/Projetos/Desktop/Horus/dist/Horus.jar-HorusPU login successful
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Object: FRANCISCO VIEIRA is not a known entity type.
at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.registerNewObjectForPersist(UnitOfWorkImpl.java:3212)
at oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerImpl.persist(EntityManagerImpl.java:205)
at horus.ui.ParametrosUI$1.run(ParametrosUI.java:82)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
O que estou fazendo errado?