我使用带有openJPA的蓝图DSL的jBoss Fuse 6.1.0。我使用容器管理事务(JTA)和Aspects管理的事务处理提交和回滚截至目前
我有以下作为JPA实体的类。
@Entity
@Table(name="CLIENT")
@NamedQuery(name="Client.findAll", query="SELECT c FROM Client c")
public class Client implements Serializable {
private static final long serialVersionUID = 1L;
//Had to add this for avoiding exception. And it works as expected
//Dummy constructor for JPA - Workaround
public Client(String s1, String s2){}
@Column(name="requestid", unique=true,nullable=false)
private String requestId;
@Id
@Column(name="clientid", unique=true, nullable=false, length=128)
private String clientId;
@OneToOne(fetch=FetchType.LAZY)
@JoinColumn(name="REQUESTID", nullable=false)
private RoccoRequest roccoRequest;
//bi-directional One-To-Many association to ClientGroup
@OneToMany(mappedBy="client",fetch=FetchType.LAZY)
private List<ClientGroup> clientGroups;
....
,...
...
}
@Entity
@Embeddable
@Table(name="CLIENTGROUP")
@NamedQuery(name="ClientGroup.findAll", query="SELECT c FROM ClientGroup c")
public class ClientGroup implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
private ClientGroupPK id;
@Column(length=32)
private String type;
@Column(name="clientid", length=128)
private String clientId;
//bi-directional many-to-one association to Client
@ManyToOne(fetch=FetchType.EAGER)
@MapsId("clientid")
@JoinColumn(name="CLIENTID", nullable=true, insertable=false, updatable=false)
private Client client;
..
.
.
.
}
@Entity
@Table(name="ROCCOREQUEST")
@NamedQuery(name="RoccoRequest.CHECK_EXISISTING_CLIENT_DETAILS",
query="SELECT r FROM RoccoRequest r JOIN r.client c WHERE c.crmId = :crmId")
public class RoccoRequest implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name="requestid", unique=true, nullable=false, length=128)
private String requestId;
@OneToOne(mappedBy="roccoRequest", fetch=FetchType.LAZY, cascade={CascadeType.PERSIST, CascadeType.REMOVE})
private Client client;
..
..
..
CriteriaQuery<Client> criteriaQuery = criteriaBuilder.createQuery(Client.class);
Root<Client> clientRoot = criteriaQuery.from(Client.class);
//Join the Client table with the RoccoRequest table
final Join<Client, RoccoRequest> clientRoccoJoin = clientRoot.join(Client_.roccoRequest,JoinType.INNER);
final Path<String> _requestStatus = clientRoccoJoin.get(RoccoRequest_.statusCode);
final Path<String> _requestId = clientRoccoJoin.get(RoccoRequest_.requestId);
final Predicate _crmIdPredicate = criteriaBuilder.equal(clientRoot.get(Client_.crmId), CRMId);
criteriaQuery.multiselect(_requestId,_requestStatus);
criteriaQuery.where(_crmIdPredicate);
//Get list of details of existing requests for the client with the request type as ACO
clientDetails = entityManager.createQuery(criteriaQuery).getResultList();
if(null != clientDetails) for(Client clientDetail : clientDetails){
StatusBO statusDetails = new StatusBO();
statusDetails.setCode((clientDetail.getRoccoRequest().getStatusCode()));
PreInitiationBO preinitiateDetails = new PreInitiationBO();
preinitiateDetails.getCaseHeader().setRequestId(requestId);
preinitiateDetails.setStatus(statusDetails);
exisitngRequestInfo.add(preinitiateDetails);
}
我做了一些Criteria获取实体。但我得到的例外情况如下:
无法找到&#34;类com.xxx.xxx.model.Client&#34;的构造函数。同 参数类型&#34; [类java.lang.String,类java.lang.String]&#34;至 填写数据。
为什么JPA期望一个参数Constructor?它与协会有什么关系?我尝试删除OneToMany关系,但我仍然得到错误。
请注意我添加了一个对我来说毫无意义的2参数构造函数。但如果给出它,它就有效。日志根级别已启用调试。关于例外的信息非常少。
请帮忙。
答案 0 :(得分:0)
正如JBNizet指出的那样, 我通过添加带有两个字符串的多选来犯了一个愚蠢的错误,但是它有一个类型为Client.class的CrtieriaQuery。
这可以通过删除多选(不在我的情况下)或通过使用Tuples.class而不是Client.class制作CriteriaQuery和其他类型来解决,并通过元组循环并获取为tuple.get(0)等
问题已解决。谢谢@Neil和@JBNizet