我使用Flex 3.5,BlazeDS 3.2.0.3978和EJB3作为后端。有两个RPC对于这个问题很重要。第一次调用将获得ThirdParty对象的列表,这工作正常。第二次调用发生在用户点击ThirdParty时,该对象的细节(懒惰集合)被检索。大多数字段序列化后返回一个对象。我说得最多,因为出于某种原因,4个布尔字段没有被序列化,并且默认情况下通过flex被置于false。为什么BlazeDS不能序列化一些字段?
这里是java bean的:
package com.rekencentra.svc.cfos.model.security; @Entity @Table( name = "AUTH_THP", uniqueConstraints = { @UniqueConstraint(columnNames={"THP_ID", "OTH_THP_ID"}) } ) @NamedQueries({ @NamedQuery( name="allAuthorizationsForThp", query="SELECT DISTINCT c FROM AuthorisationThirdParty c " + " LEFT JOIN FETCH c.otherThirdParty thp" + " LEFT JOIN FETCH thp.goodRegulation" + " WHERE c.thirdParty.id = :id" + " AND c.authValidFrom = sysdate()" )} ) @SequenceGenerator(name="seqSerialId", sequenceName="SEQ_AUTH_THP") public class AuthorisationThirdParty extends BusinessObject { private static final long serialVersionUID = -4187381385945255374L; @ManyToOne(fetch=FetchType.LAZY, cascade = {CascadeType.REFRESH}) @JoinColumn(name="THP_ID", nullable=false) private ThirdParty thirdParty; @ManyToOne(fetch=FetchType.EAGER, cascade = {CascadeType.REFRESH}) @JoinColumn(name="OTH_THP_ID", nullable=false) private ThirdParty otherThirdParty; @Column(name="ICT_F", nullable=false) private Boolean authForTemplates; @Column(name="ICN_F", nullable=false) private Boolean authForConsignments; @Column(name="SC_F", nullable=false) private Boolean authForSalesContracts; @Column(name="PC_F", nullable=false) private Boolean authForPurchaseContracts; @Column(name="FROM_DATE", nullable=true) @Temporal(TemporalType.DATE) private Date authValidFrom; @Column(name="UNTIL_DATE", nullable=true) @Temporal(TemporalType.DATE) private Date authValidTo; public ThirdParty getThirdParty() { return thirdParty; } public void setThirdParty(ThirdParty thirdParty) { this.thirdParty = thirdParty; } public ThirdParty getOtherThirdParty() { return otherThirdParty; } public void setOtherThirdParty(ThirdParty otherThirdParty) { this.otherThirdParty = otherThirdParty; } public Date getAuthValidFrom() { return authValidFrom; } public void setAuthValidFrom(Date authValidFrom) { this.authValidFrom = authValidFrom; } public Date getAuthValidTo() { return authValidTo; } public void setAuthValidTo(Date authValidTo) { this.authValidTo = authValidTo; } public void setAuthForTemplates(Boolean authForTemplates) { this.authForTemplates = authForTemplates; } public boolean isAuthForTemplates() { return authForTemplates; } public void setAuthForConsignments(Boolean authForConsignments) { this.authForConsignments = authForConsignments; } public boolean isAuthForConsignments() { return authForConsignments; } public void setAuthForSalesContracts(Boolean authForSalesContracts) { this.authForSalesContracts = authForSalesContracts; } public boolean isAuthForSalesContracts() { return authForSalesContracts; } public void setAuthForPurchaseContracts(Boolean authForPurchaseContracts) { this.authForPurchaseContracts = authForPurchaseContracts; } public boolean isAuthForPurchaseContracts() { return authForPurchaseContracts; } }
和相应的Flex类:
package com.rekencentra.ifb.cfos.model.dto.security { [Bindable] [ExcludeClass] internal class AuthorisationThirdPartyBase extends BusinessObject { public var thirdParty:ThirdParty; public var otherThirdParty:ThirdParty; public var authForTemplates:Boolean; // missing ser. public var authForConsignments:Boolean; //missing ser. public var authForSalesContracts:Boolean; //missing ser. public var authForPurchaseContracts:Boolean; //missing ser. public var authValidFrom:Date; public var authValidTo:Date; } } package com.rekencentra.ifb.cfos.model.dto.security { [Bindable] [RemoteClass(alias="com.rekencentra.svc.cfos.model.security.AuthorisationThirdParty")] public class AuthorisationThirdParty extends AuthorisationThirdPartyBase { } }
注:我已经离开了为了方便import语句。
我已经设置blazeDS日志记录调试和所有领域,但这些布尔值显示在输出中。接下来,我尝试了一下序列化过程,但在那里迷路很容易。
很好,这个固定它。我认为布尔的getter可以是遵循javabean规范的isXXX。 – joeriMJ 2010-09-07 10:27:44
我一直认为使用公有字段而不是getter和setter的数据传输对象是序列化到BlazeDS的更直接的方式。诚然,复制所有字段会导致性能下降,但不会让数据访问层泄漏到表示层中,并且乍一看看字段名称中的不匹配值得投资。 – weltraumpirat 2012-11-26 07:14:09