首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring Roo 1.2.4: Roo_DataOnDemand方面不填充引用实体

Spring Roo 1.2.4: Roo_DataOnDemand方面不填充引用实体
EN

Stack Overflow用户
提问于 2013-10-26 06:23:15
回答 1查看 100关注 0票数 0

我已经使用roo shell创建了几个带有测试的实体:

代码语言:javascript
复制
roo> entity jpa --class ~.model.Entity1 --testAutomatically --activeRecord
roo> entity jpa --class ~.model.Entity2 --testAutomatically --activeRecord
...
roo> entity jpa --class ~.model.EntityN --testAutomatically --activeRecord

然后,我开始在我的集成开发环境(IntelliJ idea)中创建它们之间的关系,使用JPA注解(@NotNull @OneToOne,@OneToMany等)。在这个过程中,我一直在运行我的集成测试,验证数据库架构。突然,我的一个java.lang.NullPointerException测试失败了。我发现,不知何故,-initized改变了之前生成的Roo_DataOnDemand方面,因此所有引用的实体都变成了“空”roo。

我可以手动执行推入重构并初始化所有引用实体,但这太慢了。roo方面生成器发生了什么?我如何修复这个问题,以便roo生成器正确地初始化所有引用?

EN

回答 1

Stack Overflow用户

发布于 2013-10-26 06:23:15

看起来Roo在"grouping import语句“方面有问题,比如:

代码语言:javascript
复制
import javax.persistence.*

为了解决这个问题,只需在实体中扩展星号即可。示例如下。

"Buggy“实体:

代码语言:javascript
复制
...
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>();

}

该实体自动生成的方面无效(删除了不相关的详细信息):

代码语言:javascript
复制
    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);
        }

    }

固定实体导入示例:

代码语言:javascript
复制
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;

在修复之后,这是一个有效的自动生成的方面:

代码语言:javascript
复制
 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);
        }

    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19600318

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档