but i know that my database (MySQL) supports Auto Increment so i didnt use @GeneratedValue
as you see the code my persistence object is very simple but i dont y does it work just for first time :D
my persistence file
@Entity
@Table(name="user_table",schema="myschema")
public class user {
@Id
@Column(name="ID",nullable=false)
private int id;
@Column(name="USERNAME",nullable=false)
private String username;
@Column(name="PASSWORD",nullable=false)
private String password;
@Column(name="EMAIL",nullable=true)
private String email;
public User() { }
public User(int id) { this.id = id; }
public int getId() { return this.id; }
public void setId(int id) { this.id = id; }
public String getUsername() { return this.username; }
public void setUsername(String username) { this.username = username; }
public String getPassword() { return this.password; }
public void setPassword(String password) { this.password = password; }
public String getEmail() { return this.email; }
public void setEmail(String email) { this.email = email; }
my stateless EJB
try {
//this.emf = null;
this.emf = Persistence.createEntityManagerFactory("test");
this.manager = emf.createEntityManager();
this.manager.getTransaction().begin();
this.manager.persist(user);
this.manager.getTransaction().commit();
} catch (EntityExistsException ex1) {
System.out.println(ex1 + " AZ TARAFE INITIAL SERVICE BEAN");
}
finally {
try {
this.manager.close();
} catch (Exception ee) {
System.out.println(ee );
return false;
}
my persistence.xml file
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistencehttp://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="test" transaction-type="JTA">
<jta-data-source>ref</jta-data-source>
<class>persistobject.User</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties/>
</persistence-unit>
</persistence>