问题描述
我有WebService,它通过EJB获取日期,但结果是我缺少映射超类中的attibute
@Entity
@Table(name = "REASON",schema = "XXX")
@NamedQueries({
})
@requiredArgsConstructor
@Getter
@Setter
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class Reason extends SSEntity implements Serializable {
private static final long serialVersionUID = -7071943771305035766L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "REASON_ID")
private Long reasonId;
@NotNull
@Column(name = "INTERNAL_ID")
private Long internalId;
}
映射的超类
@MappedSuperclass
@requiredArgsConstructor
@EqualsAndHashCode
@ToString
public abstract class SSEntity {
@NotNull
@Version
@Column(name = "UPDATE_TIMESTAMP",nullable = false)
@Setter
@Getter(onMethod=@__({@XmlJavaTypeAdapter(XmlTimestampAdapter.class)}))
private Timestamp updateTimestamp;
}
我有列出原因的Web服务方法,但是如果我使用EJB,则不会获得更新时间戳记属性
@WebService(name = "IIntegrationInboundRemoteWSSEI",targetNamespace = "http://XXX.WebServices")
public interface WebService {
@WebMethod
List<Reason> listReasonsAllEJB() throws Exception;
@WebMethod
List<Reason> listReasonsAll() throws Exception;
}
网络服务实现
@Stateless
@WebService(
serviceName = "RemoteWebService",targetNamespace = "http://XXX.WebServices",endpointInterface = "com.azs.ws.WebService",portName = "RemoteWebServicePort"
)
public class WebServiceImpl implements WebService {
@EJB(beanName = "WsEJBImpl")
private WsEJB bean;
@Inject
private EntityManager entityManager;
@Override
public List<Reason> listReasonsAllEJB() throws Exception {
return bean.listRejectionReasonsAll();
}
@Override
public List<Reason> listReasonsAll() throws Exception {
return entityManager
.createNamedQuery("listReasons",Reason.class)
.setParameter("date",new Date())
.getResultList();
}
}
EJB如下
@Remote
public interface WsEJB {
List<Reason> listReasonsAll() throws Exception;
}
EJB实现
@Stateless
@Remote(WsEJB.class)
public class WsEJBImpl implements WsEJB {
@Inject
private EntityManager entityManager;
@Override
public List<Reason> listReasonsAll() throws Exception {
return entityManager
.createNamedQuery("listReasons",new Date())
.getResultList();
}
}
如您所见,方法 listReasonsAllEJB()和 listReasonsAll()都相同
当我用SoapUI测试这些方法时,我得到了
使用EJB时,我丢失了updateTimestamp属性,我丢失了什么?..
解决方法
我的abstarct实体类必须序列化
@MappedSuperclass
public abstract class SSEntity implements Serializable {
private static final long serialVersionUID = -5741595897057015891L;
@NotNull
@Version
@Column(name = "UPDATE_TIMESTAMP",nullable = false)
@Setter
@Getter(onMethod=@__({@XmlJavaTypeAdapter(XmlTimestampAdapter.class)}))
private Timestamp updateTimestamp;
}