Ebean Groovy getAttribute:课堂上没有这样的字段

时间:2014-04-10 03:38:18

标签: jpa groovy assert ebean spock

我有三种不同的方式从实体获取id。

e.getId()
e.getProperty('id')
InvokerHelper.getAttribute(e, 'id')

我试图以这种方式比较两个实体:

MemberEventEntity e = new MemberEventEntityBuilder().withBloomId(bloomId).build()
Ebean.save(e)

MemberEventEntity e2 = Ebean.find(MemberEventEntity.class, e.getId())    
assert e == e2

我的实体构建正确,第二个实体被正确找到,但是对象是实体bean而不是实体(过去这不是问题)。

实体:

@Entity
@Table(name = 'member_event')
@EqualsAndHashCode(excludes = ['member', 'familyMember'])
class MemberEventEntity {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    Long id

    @Version
    Long version

    @ManyToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = 'member_id', nullable = false)
    MemberEntity member

    @OneToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = 'family_member_id', nullable = true)
    FamilyMemberEntity familyMember

    @Column(name = 'event_date', nullable = false)
    LocalDate eventDate

    @Column(name = 'process_on', nullable = true)
    LocalDate processOn

    @Column(name = 'effective_date', nullable = true)
    LocalDate effectiveDate

    @Column(name = 'enrollment_available_from', nullable = false)
    LocalDate enrollmentAvailableFrom

    @Column(name = 'enrollment_available_to', nullable = false)
    LocalDate enrollmentAvailableTo

}

当我断言e == e2时,在e2上我得到一个例外:

Failed to render value due to:

groovy.lang.MissingFieldException: No such field: id for class: com.bloomhealthco.fixtures.entities.MemberEventEntity$$EntityBean$default
    at groovy.lang.MetaClassImpl.getAttribute(MetaClassImpl.java:2628)
    at groovy.lang.MetaClassImpl.getAttribute(MetaClassImpl.java:3466)
    at org.codehaus.groovy.runtime.InvokerHelper.getAttribute(InvokerHelper.java:141)
    at org.spockframework.runtime.GroovyRuntimeUtil.getAttribute(GroovyRuntimeUtil.java:262)
    at org.spockframework.runtime.condition.DiffedObjectAsBeanRenderer.render(DiffedObjectAsBeanRenderer.java:28)
    at org.spockframework.runtime.condition.ObjectRendererService.render(ObjectRendererService.java:45)
    at org.spockframework.runtime.JUnitSupervisor.renderValue(JUnitSupervisor.java:141)

很明显,调用InvokerHelper.getAttribute来满足断言。有没有理由找不到属性ID?我的实体中有什么东西被错误地创建了吗?

感谢您的帮助。

0 个答案:

没有答案