2013-10-25 32 views
0

我創建了一個夫婦與測試實體,使用Roo shell中:Spring Roo的1.2.4:Roo_DataOnDemand方面不填充參考實體

roo> entity jpa --class ~.model.Entity1 --testAutomatically --activeRecord 
roo> entity jpa --class ~.model.Entity2 --testAutomatically --activeRecord 
... 
roo> entity jpa --class ~.model.EntityN --testAutomatically --activeRecord 

然後,我開始創建它們之間的關係在我的IDE(IntelliJ想法)中,使用JPA批註(@NotNull @OneToOne,@OneToMany等)。在這個過程中,我一直在運行集成測試,驗證數據庫體系結構。突然之間,我的一個測試失敗了java.lang.NullPointerException。我發現,不知何故roo改變了以前生成的Roo_DataOnDemand方面,因此所有引用的實體都變成了「null」初始化的。

我可以執行推送重構並手動初始化所​​有引用實體,但這太慢了。 roo方向發生器發生了什麼?我該如何解決這個問題,以便roo生成器正確初始化所有引用?

回答

0

看起來像袋鼠有一個問題,「分組import語句」,如:

import javax.persistence.* 

爲了解決這個問題,只是擴大你的實體內的星號。示例如下。

「越野車」 實體:

... 
import javax.persistence.*; 
... 


@RooJavaBean 
@RooToString 
@RooJpaActiveRecord 
@RooEquals 
@ValidAdvocateCount 
public class Formation { 

    @NotNull 
    @ManyToOne 
    private Acol registrationAcol; 

    /** 
    */ 
    @NotNull 
    @OneToOne 
    private Contacts contacts; 

    /** 
    */ 
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "formation") 
    private Set<Advocate> advocates = new HashSet<Advocate>(); 

} 
該實體

無效自動生成的方面(不相關的細節移除):

privileged aspect FormationDataOnDemand_Roo_DataOnDemand { 

     declare @type: FormationDataOnDemand: @Component; 

     private List<Formation> FormationDataOnDemand.data; 

     public Formation FormationDataOnDemand.getNewTransientFormation(int index) { 
      Formation obj = new Formation(); 
      setContacts(obj, index); 
      setForm(obj, index); 
      setName(obj, index); 
      setRate(obj, index); 
      setRegistrationAcol(obj, index); 
      setResume(obj, index); 
      setReviewDate(obj, index); 
      setViews(obj, index); 
      return obj; 
     } 

     public void FormationDataOnDemand.setContacts(Formation obj, int index) { 
      Contacts contacts = null; 
      obj.setContacts(contacts); 
     } 

     public void FormationDataOnDemand.setRegistrationAcol(Formation obj, int index) { 
      Acol registrationAcol = null; 
      obj.setRegistrationAcol(registrationAcol); 
     } 

    } 

固定實體進口例如:

import javax.persistence.EnumType; 
import javax.persistence.Enumerated; 
import javax.persistence.Temporal; 
import javax.persistence.TemporalType; 
import javax.persistence.OneToOne; 
import javax.persistence.OneToMany; 
import javax.persistence.ManyToOne; 
import javax.persistence.CascadeType; 
import javax.validation.constraints.NotNull; 

而這裏是一個有效的自動生成方面,修復後:

privileged aspect FormationDataOnDemand_Roo_DataOnDemand { 

     declare @type: FormationDataOnDemand: @Component; 

     private List<Formation> FormationDataOnDemand.data; 

     @Autowired 
     ContactsDataOnDemand FormationDataOnDemand.contactsDataOnDemand; 

     @Autowired 
     AcolDataOnDemand FormationDataOnDemand.acolDataOnDemand; 

     public Formation FormationDataOnDemand.getNewTransientFormation(int index) { 
      Formation obj = new Formation(); 
      setContacts(obj, index); 
      setForm(obj, index); 
      setName(obj, index); 
      setRate(obj, index); 
      setRegistrationAcol(obj, index); 
      setResume(obj, index); 
      setReviewDate(obj, index); 
      setViews(obj, index); 
      return obj; 
     } 

     public void FormationDataOnDemand.setContacts(Formation obj, int index) { 
      Contacts contacts = contactsDataOnDemand.getSpecificContacts(index); 
      obj.setContacts(contacts); 
     } 

     public void FormationDataOnDemand.setRegistrationAcol(Formation obj, int index) { 
      Acol registrationAcol = acolDataOnDemand.getRandomAcol(); 
      obj.setRegistrationAcol(registrationAcol); 
     } 

    }