是这样的,我用实体BEAN加到数据库的东西,等我重起完应用服务器就全都没有了,不知道为什么,关了的时候我看还在的,好像是当再次加载我写的EJB的时候就全删了,为什么呢实体:
@Entity
@Table(name="acount"
,catalog="atm"
, uniqueConstraints = { }
)
@NamedQuery(name="findThem",query="select a from Account a")
public class Account implements java.io.Serializable {
// Fields private String acountId;
private String owerName;
private String passwd;
private Double allMoney;
// Constructors /** default constructor */
public Account() {
} /** minimal constructor */
public Account(String acountId) {
this.acountId = acountId;
}
/** full constructor */
public Account(String acountId, String owerName, String passwd, Double allMoney) {
this.acountId = acountId;
this.owerName = owerName;
this.passwd = passwd;
this.allMoney = allMoney;
}
// Property accessors
@Id
@Column(name="AcountId", unique=true, nullable=false, insertable=true, updatable=true, length=10) public String getAcountId() {
return this.acountId;
}
public void setAcountId(String acountId) {
this.acountId = acountId;
}
@Column(name="OwerName", unique=false, nullable=true, insertable=true, updatable=true, length=20) public String getOwerName() {
return this.owerName;
}
public void setOwerName(String owerName) {
this.owerName = owerName;
}
@Column(name="passwd", unique=false, nullable=true, insertable=true, updatable=true, length=18) public String getPasswd() {
return this.passwd;
}
public void setPasswd(String passwd) {
this.passwd = passwd;
}
@Column(name="AllMoney", unique=false, nullable=true, insertable=true, updatable=true, precision=22, scale=0) public Double getAllMoney() {
return this.allMoney;
}
public void setAllMoney(Double allMoney) {
this.allMoney = allMoney;
}会话BEAN:
@Stateful
@Remote({QueryBalanceRemote.class})
@RemoteBinding (jndiBinding="QueryBalance")
@Interceptors(QueryBalanceCallback.class)
public class QueryBalance implements QueryBalanceRemote{
@PersistenceContext(type=PersistenceContextType.EXTENDED ,unitName="manager" )
@Basic
private EntityManager manager;
private Account acc=null;
public Account openAccount(String owerName,String passwd){
Account acc = new Account();
acc.setAcountId(new Long(System.nanoTime()).toString().substring(0, 10));
acc.setOwerName(owerName);
acc.setAllMoney(0.0);
acc.setPasswd(passwd);
// try{
// userTx.begin();
manager.persist(acc);
// System.out.println("persistence !");
// userTx.commit();
// }catch(Exception e){
// try {
// userTx.rollback();
// } catch (Exception e1) {
// e1.printStackTrace();
// }
// e.printStackTrace();
// }
this.acc = acc;
return acc;
}
@Remove
public void remove(){
manager.persist(acc);
System.out.println("QueryBalance removed! OwerName is "+acc.getOwerName());
}
}
@Entity
@Table(name="acount"
,catalog="atm"
, uniqueConstraints = { }
)
@NamedQuery(name="findThem",query="select a from Account a")
public class Account implements java.io.Serializable {
// Fields private String acountId;
private String owerName;
private String passwd;
private Double allMoney;
// Constructors /** default constructor */
public Account() {
} /** minimal constructor */
public Account(String acountId) {
this.acountId = acountId;
}
/** full constructor */
public Account(String acountId, String owerName, String passwd, Double allMoney) {
this.acountId = acountId;
this.owerName = owerName;
this.passwd = passwd;
this.allMoney = allMoney;
}
// Property accessors
@Id
@Column(name="AcountId", unique=true, nullable=false, insertable=true, updatable=true, length=10) public String getAcountId() {
return this.acountId;
}
public void setAcountId(String acountId) {
this.acountId = acountId;
}
@Column(name="OwerName", unique=false, nullable=true, insertable=true, updatable=true, length=20) public String getOwerName() {
return this.owerName;
}
public void setOwerName(String owerName) {
this.owerName = owerName;
}
@Column(name="passwd", unique=false, nullable=true, insertable=true, updatable=true, length=18) public String getPasswd() {
return this.passwd;
}
public void setPasswd(String passwd) {
this.passwd = passwd;
}
@Column(name="AllMoney", unique=false, nullable=true, insertable=true, updatable=true, precision=22, scale=0) public Double getAllMoney() {
return this.allMoney;
}
public void setAllMoney(Double allMoney) {
this.allMoney = allMoney;
}会话BEAN:
@Stateful
@Remote({QueryBalanceRemote.class})
@RemoteBinding (jndiBinding="QueryBalance")
@Interceptors(QueryBalanceCallback.class)
public class QueryBalance implements QueryBalanceRemote{
@PersistenceContext(type=PersistenceContextType.EXTENDED ,unitName="manager" )
@Basic
private EntityManager manager;
private Account acc=null;
public Account openAccount(String owerName,String passwd){
Account acc = new Account();
acc.setAcountId(new Long(System.nanoTime()).toString().substring(0, 10));
acc.setOwerName(owerName);
acc.setAllMoney(0.0);
acc.setPasswd(passwd);
// try{
// userTx.begin();
manager.persist(acc);
// System.out.println("persistence !");
// userTx.commit();
// }catch(Exception e){
// try {
// userTx.rollback();
// } catch (Exception e1) {
// e1.printStackTrace();
// }
// e.printStackTrace();
// }
this.acc = acc;
return acc;
}
@Remove
public void remove(){
manager.persist(acc);
System.out.println("QueryBalance removed! OwerName is "+acc.getOwerName());
}
}
persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence 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/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<persistence-unit name="manager">
<jta-data-source>java:/mysql</jta-data-source>
<properties>
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
</properties>
</persistence-unit>
</persistence>