The following code does persist data (orders and order lines) to database, and I did see that. The problem is that the data were all erased once jboss is restarted. How can I change that?
I have a persistencein META-INF directory:
<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="sample">
<jta-data-source>java:/DefaultDS</jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
</properties>
</persistence-unit>
</persistence>
in my stateful bean I have this code, and checkout was called from outside:
package org.jboss.tutorial.entity.bean;
import javax.ejb.Remote;
import javax.ejb.Remove;
import javax.ejb.Stateful;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContext;
@Stateful
@Remote(ShoppingCart.class)
public class ShoppingCartBean implements ShoppingCart, java.io.Serializable
{
@PersistenceContext(unitName="sample")
private EntityManager manager;
private Order order;
public void buy(String product, int quantity, double price)
{
if (order == null) order = new Order();
order.addPurchase(product, quantity, price);
}
public Order getOrder()
{
return order;
}
@Remove
public void checkout()
{
manager.persist(order);
}
}