public void Setlineitems (collection<lineitem> lineitems)
{
This.lineitems = LineItems;
}
}
Added a lot of English notes, I hope to understand.
@Table (name = "Purchase_order")
Named database (JBoss database for hsqldb) in the corresponding table name, default to class name, such as the following LineItem there is no @table. (Order.java, Lineitem.java are both O/R maps, worth comparing)
@Id (generate = Generatortype.auto)
Increment, same as in the database. Must be annotated on the Getter method.
Relationship: Order and LineItem are 1 pairs of relationships. The cascadetype.all here is to indicate that when an order is instantiated, both the LineItem should be established at the same time. In the annotation, the different cascadetype are defined according to the difference of the time between the two sets.
Lineitem.java
Package Org.jboss.tutorial.entity.bean;
Import javax.persistence.Entity;
Import Javax.persistence.GeneratorType;
Import Javax.persistence.Id;
Import Javax.persistence.JoinColumn;
Import Javax.persistence.ManyToOne;
Import javax.persistence.Entity;
@Entity
public class LineItem implements Java.io.Serializable
{
private int id;
private double subtotal;
private int quantity;
Private String product;
Private order;
@Id (generate = Generatortype.auto)
public int getId ()
{
return ID;
}
public void setId (int id)
{
This.id = ID;
}
Public double getsubtotal ()
{
return subtotal;
}
public void Setsubtotal (double subtotal)
{
This.subtotal = subtotal;
}
public int getquantity ()
{
return quantity;
}
public void setquantity (int quantity)
{
this.quantity = quantity;
}
Public String getproduct ()
{
return product;
}
public void Setproduct (String product)
{
This.product = product;
}
The @JoinColumn specifies the foreign key column within the LineItem table.
@ManyToOne
@JoinColumn (name = "order_id")
Public Order GetOrder ()
{
return order;
}
public void Setorder (order order)
{
This.order = order;
}
}
Shoppingcart.java
Package Org.jboss.tutorial.entity.bean;
Import Javax.ejb.Remote;
Import Javax.ejb.Remove;
@Remote
public interface ShoppingCart
{
void Buy (String product, int quantity, double);
Order GetOrder ();
@Remove void Checkout ();
}
Shoppingcartbean.java
Package Org.jboss.tutorial.entity.bean;
Import Javax.persistence.EntityManager;
Import Javax.ejb.Inject;
Import Javax.ejb.Remove;
Import javax.ejb.Stateful;
@Stateful
public class Shoppingcartbean implements ShoppingCart
{
@Inject
Private Entitymanager Manager; The Entitymanager is used to do querying,
Creating, find by primary key, and removal of entity beans.
Private 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);
}
}
Entitymanager can be used to query, create, delete entity beans, insert a entitymanager, and save data in a database when the last user leaves, which is equivalent to saving an object. After running the Client.java, you can see two tables with Purchase_order and LineItem on the hsqldb. Hypersonicdatabase, find Startdatabasemanager and then there is an invoke, click on the access to HSQLDB.
Here attached log4j.properties in Jboss-ejb-3.0_preview_5.zip without this always shows a lack of appender. With this, a record.log log file will be generated in this directory.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.