2013-11-22 57 views
0

我有3個實體客戶,數據和信息。實體之間的關係是oneToMany是這樣的:使用MySQL Query獲取客戶信息

public class Customer implements Serializable { 
... 
@OneToMany 
private List<Data> datas; 
... 

public class Data implements Serializable { 
... 
@OneToMany(mappedBy = "dataBase") 
    private List<Information> informations; 
    @ManyToOne 
    private Customer customer; 
.. 

public class Information implements Serializable { 
... 
@ManyToOne 
    private Data dataBase; 
... 

現在我希望每個登錄的客戶只能看到自己的信息。 我想用abql使用JPQL命名查詢。 所以我寫的信息

public List<Information> getInformations() { 
     FacesContext context = FacesContext.getCurrentInstance(); 
     HttpServletRequest request = (HttpServletRequest)  context.getExternalContext().getRequest(); 
     HttpSession session = request.getSession(false); 
     String idCustomer = (String) session.getAttribute("idCustomer"); 
     Customer cust = customerBusinessLocal.findById(idCustomer); 
     List<Data> datas=dataBusinessLocal.findByCustomer(cust); 
     return InformationBusinessLocal.informations(datas);  
    } 

的manged Bean的這個方法,但我得到javax.ejb.EJBTransactionRolledbackException

+0

如何使用教程開始? – Strawberry

+0

你知道任何有用的嗎? –

+0

我相信任何使用適當關鍵字找到的教程都會很有用。 – Strawberry

回答

-1
public List<Information`enter code here`> getInformations() { 
     FacesContext context = FacesContext.getCurrentInstance(); 
     HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest(); 
     HttpSession session = request.getSession(false); 
     String idCustomer = (String) session.getAttribute("idCustomer"); 
     System.out.println(idCustomer + " this is it"); 
     Customer cust = customerBusinessLocal.findById(idCustomer); 
     List<Data> datas = dataBusinessLocal.findByCustomer(cust); 
     for(Data d: datas) 
     {   
      for(Information i: d.getInformations()){   
       informations.add(i); 
     } 
      } 
     return informations; 
    }