[jboss-user] [EJB 3.0] - ERM to Entity relationship problem
te-bachi
do-not-reply at jboss.com
Fri Jan 26 07:46:26 EST 2007
I was developing a C/C++ application and I want to migrate this application to Java EE 5 / EJB 3.0.
I use an oracle database to do persistency. I create 3 entities and mapped it via annotation to a relational database.
My ERM can't be changed anymore, but all this relationship types in the book "EJB 3.0" written by Bill Burke can't applied.
Environment:
o Java 1.5.0_09
o IntelliJ IDEA 6.0.4
o JBoss 4.0.5 AS (JEMS Installer with ejb3)
o Windows XP SP2
o Oracle 10.1.0.4.0 (Solaris 8)
ERM:
Independent Code:
Client (Struts Action):
| public class PaymentSearchAction extends Action {
| public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
| StringBuffer buffer = new StringBuffer();
|
| try {
| InitialContext ctx = new InitialContext();
| UserTransaction trans = (UserTransaction) ctx.lookup("java:comp/UserTransaction");
| trans.begin();
| AuditSearch search = (AuditSearch) ctx.lookup("JApollo/AuditSearchBean/local");
| AuditSearchTemplateEntity templ = search.getTemplate(BigInteger.valueOf(1));
|
| buffer.append("id: ");
| buffer.append(templ.getTemplateId());
|
| buffer.append("key: ");
| buffer.append(templ.getKey());
|
| buffer.append("<br>");
|
| List<AuditSearchAssignEntity> searchAssignList = templ.getSearchAssignList(); // <== Exception raised!
| AuditSearchAssignEntity searchAssign;
| AuditSearchCriteriaEntity criteria;
| for (int i = 0; i < searchAssignList.size(); i++) {
| searchAssign = searchAssignList.get(i);
| criteria = searchAssign.getCriteria();
|
| buffer.append("id: ");
| buffer.append(criteria.getCriteriaId());
|
| buffer.append("is-splitted: ");
| buffer.append(criteria.getIsSplitted());
|
| buffer.append("key: ");
| buffer.append(criteria.getKey());
|
| buffer.append("type: ");
| buffer.append(criteria.getType());
|
| buffer.append("<br>");
| }
| trans.commit();
| } catch (Exception e) {
| buffer.append("Error: ");
| buffer.append(e.getMessage());
| e.printStackTrace();
| }
|
| request.setAttribute("test", buffer.toString());
|
| return mapping.getInputForward();
| }
| }
|
Stateless Session Bean:
| @Stateless
| public class AuditSearchBean implements AuditSearch {
| @PersistenceContext
| EntityManager em;
|
| public AuditSearchTemplateEntity getTemplate(BigInteger id) {
| return em.find(AuditSearchTemplateEntity.class, id);
| }
| }
|
Template Entity:
| @Entity(name = "AuditSearchTemplateEntity")
| @Table(schema = "UGIS1004", name = "GIS_T_AUDIT_SEARCH_TEMPL")
| public class AuditSearchTemplateEntity {
| private BigInteger templateId;
| private BigInteger key;
| private List<AuditSearchAssignEntity> auditSearchAssignEntities;
|
| @Id
| @Column(name = "TEMPLATE_ID", nullable = false, length = 38)
| public BigInteger getTemplateId() {
| return templateId;
| }
|
| public void setTemplateId(BigInteger templateId) {
| this.templateId = templateId;
| }
|
| @Column(name = "KEY", nullable = false, length = 4)
| public BigInteger getKey() {
| return key;
| }
|
| public void setKey(BigInteger key) {
| this.key = key;
| }
|
| @OneToMany(mappedBy = "templateId")
| public List<AuditSearchAssignEntity> getAuditSearchAssignEntities() {
| return auditSearchAssignEntities;
| }
|
| public void setAuditSearchAssignEntities(List<AuditSearchAssignEntity> auditSearchAssignEntities) {
| this.auditSearchAssignEntities = auditSearchAssignEntities;
| }
|
| public boolean equals(Object o) {
| if (this == o) return true;
| if (o == null || getClass() != o.getClass()) return false;
|
| AuditSearchTemplateEntity that = (AuditSearchTemplateEntity) o;
|
| if (templateId != null ? !templateId.equals(that.templateId) : that.templateId != null) return false;
|
| return true;
| }
|
| public int hashCode() {
| return (templateId != null ? templateId.hashCode() : 0);
| }
| }
|
Criteria Entity:
| @Entity(name = "AuditSearchCriteriaEntity")
| @Table(schema = "UGIS1004", name = "GIS_T_AUDIT_SEARCH_CRIT")
| public class AuditSearchCriteriaEntity {
| private BigInteger criteriaId;
| private BigInteger key;
| private BigInteger type;
| private BigInteger isSplitted;
| private List<AuditSearchAssignEntity> auditSearchAssignEntities;
|
| @Id
| @Column(name = "CRITERIA_ID", nullable = false, length = 38)
| public BigInteger getCriteriaId() {
| return criteriaId;
| }
|
| public void setCriteriaId(BigInteger criteriaId) {
| this.criteriaId = criteriaId;
| }
|
| @Column(name = "KEY", nullable = false, length = 4)
| public BigInteger getKey() {
| return key;
| }
|
| public void setKey(BigInteger key) {
| this.key = key;
| }
|
| @Column(name = "TYPE", nullable = false, length = 4)
| public BigInteger getType() {
| return type;
| }
|
| public void setType(BigInteger type) {
| this.type = type;
| }
|
| @Column(name = "IS_SPLITTED", nullable = false, length = 1)
| public BigInteger getIsSplitted() {
| return isSplitted;
| }
|
| public void setIsSplitted(BigInteger splitted) {
| isSplitted = splitted;
| }
|
| @OneToMany(mappedBy = "criteriaId")
| public List<AuditSearchAssignEntity> getAuditSearchAssignEntities() {
| return auditSearchAssignEntities;
| }
|
| public void setAuditSearchAssignEntities(List<AuditSearchAssignEntity> auditSearchAssignEntities) {
| this.auditSearchAssignEntities = auditSearchAssignEntities;
| }
|
| public boolean equals(Object o) {
| if (this == o) return true;
| if (o == null || getClass() != o.getClass()) return false;
|
| AuditSearchCriteriaEntity that = (AuditSearchCriteriaEntity) o;
|
| if (criteriaId != null ? !criteriaId.equals(that.criteriaId) : that.criteriaId != null) return false;
|
| return true;
| }
|
| public int hashCode() {
| return (criteriaId != null ? criteriaId.hashCode() : 0);
| }
| }
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4006780#4006780
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4006780
More information about the jboss-user
mailing list