2012-11-07 3 views
1

세 클래스가 서로 연결되어 있습니다. Order, OrderDetail 및 Product. 내 JPA 프로젝트에서 다음을 수행합니다.ejb3에서 전체 엔티티가 검색되지 않습니다.

@Override 
    public Order getOrderById(String orderID) { 
     Order order = (Order) 

      em.createQuery("select A from Order A where A.orderId = ?1") 
      .setParameter(1, orderID) 
      .getSingleResult(); 
     return order;  
    } 

모든 정보가 검색됩니다. 그러나, 그것을 ebj 프로젝트로 옮길 때. 나는 오직 주문 만 받고 그게 전부입니다. 그러나 모든 클래스는 persistence.xml 파일 (JPA와 ejb3)에 포함되어 있습니다. 왜 그런데 어떻게 해결해야합니까? 세 개의 클래스가 아래에 표시됩니다. Oracle Weblogic 10.3.3을 사용하고 있습니다. 다시 시작하고 서버를 지우려고했지만 작동하지 않습니다.

*package eshop; 

import java.io.Serializable; 
import javax.persistence.*; 
import java.util.ArrayList; 
import java.util.List;* 


/** 
* The persistent class for the orders database table. 
* 
*/ 
@Entity 
@Table(name="orders") 
public class Order implements Serializable { 
    private static final long serialVersionUID = 1L; 

    @Id 
    @Column(name="order_id") 
    private String orderId; 

    @Column(name="cc_expiry") 
    private String ccExpiry; 

    @Column(name="cc_name") 
    private String ccName; 

    @Column(name="cc_number") 
    private String ccNumber; 

    @Column(name="delivery_address") 
    private String deliveryAddress; 

    @Column(name="delivery_name") 
    private String deliveryName; 

    @Column(name="delivery_surname") 
    private String deliverySurname; 

    private String status; 

    //bi-directional many-to-one association to OrderDetail 
    @OneToMany(mappedBy="order", cascade=CascadeType.PERSIST) 
    private List<OrderDetail> orderDetails = new ArrayList<OrderDetail>(); 

    public void addOrUpdateOrderDetail(Product product) { 
     this.orderDetails.add(new OrderDetail(product)); 


    } 







    public Order() { 
    } 

    public String getOrderId() { 
     return this.orderId; 
    } 

    public void setOrderId(String orderId) { 
     this.orderId = orderId; 
    } 

    public String getCcExpiry() { 
     return this.ccExpiry; 
    } 

    public void setCcExpiry(String ccExpiry) { 
     this.ccExpiry = ccExpiry; 
    } 

    public String getCcName() { 
     return this.ccName; 
    } 

    public void setCcName(String ccName) { 
     this.ccName = ccName; 
    } 

    public String getCcNumber() { 
     return this.ccNumber; 
    } 

    public void setCcNumber(String ccNumber) { 
     this.ccNumber = ccNumber; 
    } 

    public String getDeliveryAddress() { 
     return this.deliveryAddress; 
    } 

    public void setDeliveryAddress(String deliveryAddress) { 
     this.deliveryAddress = deliveryAddress; 
    } 

    public String getDeliveryName() { 
     return this.deliveryName; 
    } 

    public void setDeliveryName(String deliveryName) { 
     this.deliveryName = deliveryName; 
    } 

    public String getDeliverySurname() { 
     return this.deliverySurname; 
    } 

    public void setDeliverySurname(String deliverySurname) { 
     this.deliverySurname = deliverySurname; 
    } 

    public String getStatus() { 
     return this.status; 
    } 

    public void setStatus(String status) { 
     this.status = status; 
    } 

    public List<OrderDetail> getOrderDetails() { 
     return this.orderDetails; 
    } 

    public void setOrderDetails(List<OrderDetail> orderDetails) { 
     this.orderDetails = orderDetails; 
    } 

} 


package eshop; 

import java.io.Serializable; 
import javax.persistence.*; 
import java.math.BigDecimal; 


/** 
* The persistent class for the order_details database table. 
* 
*/ 
@Entity 
@Table(name="order_details") 
public class OrderDetail implements Serializable { 
    private static final long serialVersionUID = 1L; 

@GeneratedValue(strategy=GenerationType.AUTO) 
private int id; 

private BigDecimal price; 

private int quantity; 

//bi-directional many-to-one association to Order 
@ManyToOne 
@JoinColumn(name="order_id") 
private Order order; 

//bi-directional many-to-one association to Product 
@ManyToOne 
@JoinColumn(name="product_id") 
private Product product; 

@Id 
private int product_id; 

public OrderDetail() { 
} 

public OrderDetail (Integer ProductId,Product product,Integer productQuantity,BigDecimal price, Order order) { 
     this.price= price; 
     this.product_id = ProductId; 
     this.product = product; 
     this.quantity = productQuantity; 
     this.order = order; 
     } 

    public OrderDetail(Product product1) { 
    product_id = product1.getCategoryId(); 
    price = product1.getPrice(); 
    quantity = 1; 
    product = product1; 

    } 

    public int getId() { 
     return this.id; 
    } 

    public void setId(int id) { 
     this.id = id; 
    } 

    public BigDecimal getPrice() { 
     return this.price; 
    } 

    public void setPrice(BigDecimal price) { 
     this.price = price; 
    } 

    public int getQuantity() { 
     return this.quantity; 
    } 

    public void setQuantity(int quantity) { 
     this.quantity = quantity; 
    } 

    public Order getOrder() { 
     return this.order; 
    } 

    public void setOrder(Order order) { 
     this.order = order; 
    } 

    public Product getProduct() { 
     return this.product; 
    } 

    public void setProduct(Product product) { 
     this.product = product; 
    } 

    public int getProduct_id() { 
     return product_id; 
    } 

    public void setProduct_id(int product_id) { 
     this.product_id = product_id; 
    } 

} 

package eshop; 

import java.io.Serializable; 
import javax.persistence.*; 
import java.math.BigDecimal; 


/** 
* The persistent class for the products database table. 
* 
*/ 
@Entity 
@Table(name="products") 
public class Product implements Serializable { 
    private static final long serialVersionUID = 1L; 

    @Id 
    @Column(name="product_id") 
    private int productId; 

    @Column(name="category_id") 
    private int categoryId; 

    @Lob 
    private String descr; 

    private BigDecimal price; 

    @Column(name="product_name") 
    private String productName; 

    private int quantity; 

    public Product() { 
    } 

    public int getProductId() { 
     return this.productId; 
    } 

    public void setProductId(int productId) { 
     this.productId = productId; 
    } 

    public int getCategoryId() { 
     return this.categoryId; 
    } 

    public void setCategoryId(int categoryId) { 
     this.categoryId = categoryId; 
    } 

    public String getDescr() { 
     return this.descr; 
    } 

    public void setDescr(String descr) { 
     this.descr = descr; 
    } 

    public BigDecimal getPrice() { 
     return this.price; 
    } 

    public void setPrice(BigDecimal price) { 
     this.price = price; 
    } 

    public String getProductName() { 
     return this.productName; 
    } 

    public void setProductName(String productName) { 
     this.productName = productName; 
    } 

    public int getQuantity() { 
     return this.quantity; 
    } 

    public void setQuantity(int quantity) { 
     this.quantity = quantity; 
    } 

} 

답변

0

나는 트랜잭션 유형 JTA를 ejb의 web.xml 파일에 추가해야했습니다.

0

"JPA 프로젝트에서 EJB 프로젝트로 코드를 이동하는 것의 의미를 이해하지 못합니다."또한 문제에 대해 좀 더 구체적으로 설명 할 수 있습니까? getOrderById를 호출하는 코드는 어디?()?

나는 그것이 웹 계층에 있다고 생각한다.이 경우, 난 당신이 에 문제가 유형를 가져올 수 있다는 것을 생각한다. 기본적으로 정의된다 LAZY (EAGERVS)로.

이 t JPA 처음에만로드된다는 것을 의미 그는 루트 객체. JPA가 다른 요청을 발행 할 링크 된 객체에 액세스하려고 할 때입니다. 이는 개발자에게 투명하고 중요한 요구 사항을 제공합니다. EJB 계층에있는 경우에만 작동합니다. 웹 티어에 루트 객체를 반환 한 경우 JPA에서 더 이상 제어하지 않습니다. 즉, 종속 오브젝트가로드되지 않은 경우 액세스 할 때 널 값을 얻게됩니다 (JPA가 루프에서 빠져 있기 때문에 후속 요청이 DB로 보내지지 않습니다).

관련 문제