[EJB 3.0] - Re: ERM to Entity relationship problem
by te-bachi
Fourth approach:
Exception:
| 12:20:59,153 INFO [STDOUT] Hibernate: select auditsearc0_.TEMPLATE_ID as TEMPLATE1_23_0_, auditsearc0_.KEY as KEY23_0_ from UGIS1004.GIS_T_AUDIT_SEARCH_TEMPL auditsearc0_ where auditsearc0_.TEMPLATE_ID=?
| 12:20:59,449 INFO [STDOUT] Hibernate: select auditsearc0_.templateId_TEMPLATE_ID as templateId6_2_, auditsearc0_.CRITERIA_ID as CRITERIA1_2_, auditsearc0_.TEMPLATE_ID as TEMPLATE2_2_, auditsearc0_.CRITERIA_ID as CRITERIA1_21_1_, auditsearc0_.TEMPLATE_ID as TEMPLATE2_21_1_, auditsearc0_.criteriaId_CRITERIA_ID as criteriaId5_21_1_, auditsearc0_.templateId_TEMPLATE_ID as templateId6_21_1_, auditsearc0_.CRITERIA_ORDER as CRITERIA3_21_1_, auditsearc0_.IS_SPECIFIC as IS4_21_1_, auditsearc1_.CRITERIA_ID as CRITERIA1_22_0_, auditsearc1_.KEY as KEY22_0_, auditsearc1_.TYPE as TYPE22_0_, auditsearc1_.IS_SPLITTED as IS4_22_0_ from UGIS1004.GIS_T_AUDIT_SEARCH_ASSIGN auditsearc0_ inner join UGIS1004.GIS_T_AUDIT_SEARCH_CRIT auditsearc1_ on auditsearc0_.criteriaId_CRITERIA_ID=auditsearc1_.CRITERIA_ID where auditsearc0_.templateId_TEMPLATE_ID=?
| 12:20:59,496 WARN [JDBCExceptionReporter] SQL Error: 904, SQLState: 42000
| 12:20:59,496 ERROR [JDBCExceptionReporter] ORA-00904: "AUDITSEARC0_"."CRITERIAID_CRITERIA_ID": ungültiger Bezeichner
|
| 12:20:59,496 ERROR [STDERR] org.hibernate.exception.SQLGrammarException: could not initialize a collection: [gis.audit.entity.AuditSearchTemplateEntity.auditSearchAssignEntities#1]
| at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
| at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
| at org.hibernate.loader.Loader.loadCollection(Loader.java:1925)
| [...]
|
| @Entity(name = "AuditSearchAssignEntity")
| @Table(schema = "UGIS1004", name = "GIS_T_AUDIT_SEARCH_ASSIGN")
| public class AuditSearchAssignEntity {
| private AuditSearchAssignPK pk;
| private BigInteger criteriaOrder;
| private BigInteger isSpecific;
| private AuditSearchCriteriaEntity criteriaId;
| private AuditSearchTemplateEntity templateId;
|
| @EmbeddedId
| public AuditSearchAssignPK getPk() {
| return pk;
| }
|
| public void setPk(AuditSearchAssignPK pk) {
| this.pk = pk;
| }
|
| @ManyToOne
| @JoinColumn(referencedColumnName = "CRITERIA_ID", nullable = false)
| public AuditSearchCriteriaEntity getCriteriaId() {
| return criteriaId;
| }
|
| public void setCriteriaId(AuditSearchCriteriaEntity criteriaId) {
| this.criteriaId = criteriaId;
| }
|
| @ManyToOne
| @JoinColumn(referencedColumnName = "TEMPLATE_ID", nullable = false)
| public AuditSearchTemplateEntity getTemplateId() {
| return templateId;
| }
|
| public void setTemplateId(AuditSearchTemplateEntity templateId) {
| this.templateId = templateId;
| }
|
| @Column(name = "CRITERIA_ORDER", nullable = false, length = 4)
| public BigInteger getCriteriaOrder() {
| return criteriaOrder;
| }
|
| public void setCriteriaOrder(BigInteger criteriaOrder) {
| this.criteriaOrder = criteriaOrder;
| }
|
| @Column(name = "IS_SPECIFIC", nullable = false, length = 1)
| public BigInteger getIsSpecific() {
| return isSpecific;
| }
|
| public void setIsSpecific(BigInteger specific) {
| isSpecific = specific;
| }
| }
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4006786#4006786
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4006786
19 years, 2 months
[EJB 3.0] - Re: ERM to Entity relationship problem
by te-bachi
Third approach:
Exception:
| javax.persistence.PersistenceException: org.hibernate.MappingException: Repeated column in mapping for entity: gis.audit.entity.AuditSearchAssignEntity column: CRITERIA_ID (should be mapped with insert="false" update="false")
| at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:698)
| at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:127)
| at org.jboss.ejb3.entity.PersistenceUnitDeployment.start(PersistenceUnitDeployment.java:264)
| [...]
|
Assign PK:
| @Embeddable
| public class AuditSearchAssignPK implements Serializable {
| private BigInteger criteriaId;
| private BigInteger templateId;
|
| public AuditSearchAssignPK() {
| //
| }
|
| public AuditSearchAssignPK(BigInteger criteriaId, BigInteger templateId) {
| this.criteriaId = criteriaId;
| this.templateId = templateId;
| }
|
| @Column(name = "CRITERIA_ID", nullable = false, length = 38)
| public BigInteger getCriteriaId() {
| return criteriaId;
| }
|
| public void setCriteriaId(BigInteger criteriaId) {
| this.criteriaId = criteriaId;
| }
|
| @Column(name = "TEMPLATE_ID", nullable = false, length = 38)
| public BigInteger getTemplateId() {
| return templateId;
| }
|
| public void setTemplateId(BigInteger templateId) {
| this.templateId = templateId;
| }
|
| public boolean equals(Object obj) {
| if (this == obj) return true;
| if (obj == null || getClass() != obj.getClass()) return false;
|
| AuditSearchAssignPK that = (AuditSearchAssignPK) obj;
|
| if (criteriaId != null ? !criteriaId.equals(that.criteriaId) : that.criteriaId != null) return false;
| if (templateId != null ? !templateId.equals(that.templateId) : that.templateId != null) return false;
|
| return true;
| }
|
| public int hashCode() {
| return criteriaId.hashCode() + templateId.hashCode();
| }
| }
|
Assign Entity:
| @Entity(name = "AuditSearchAssignEntity")
| @Table(schema = "UGIS1004", name = "GIS_T_AUDIT_SEARCH_ASSIGN")
| public class AuditSearchAssignEntity {
| private AuditSearchAssignPK pk;
| private BigInteger criteriaOrder;
| private BigInteger isSpecific;
| private AuditSearchCriteriaEntity criteriaId;
| private AuditSearchTemplateEntity templateId;
|
| @EmbeddedId
| public AuditSearchAssignPK getPk() {
| return pk;
| }
|
| public void setPk(AuditSearchAssignPK pk) {
| this.pk = pk;
| }
|
| @ManyToOne
| @JoinColumn(name = "CRITERIA_ID", referencedColumnName = "CRITERIA_ID", nullable = false)
| public AuditSearchCriteriaEntity getCriteriaId() {
| return criteriaId;
| }
|
| public void setCriteriaId(AuditSearchCriteriaEntity criteriaId) {
| this.criteriaId = criteriaId;
| }
|
| @ManyToOne
| @JoinColumn(name = "TEMPLATE_ID", referencedColumnName = "TEMPLATE_ID", nullable = false)
| public AuditSearchTemplateEntity getTemplateId() {
| return templateId;
| }
|
| public void setTemplateId(AuditSearchTemplateEntity templateId) {
| this.templateId = templateId;
| }
|
| @Column(name = "CRITERIA_ORDER", nullable = false, length = 4)
| public BigInteger getCriteriaOrder() {
| return criteriaOrder;
| }
|
| public void setCriteriaOrder(BigInteger criteriaOrder) {
| this.criteriaOrder = criteriaOrder;
| }
|
| @Column(name = "IS_SPECIFIC", nullable = false, length = 1)
| public BigInteger getIsSpecific() {
| return isSpecific;
| }
|
| public void setIsSpecific(BigInteger specific) {
| isSpecific = specific;
| }
| }
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4006784#4006784
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4006784
19 years, 2 months
[EJB 3.0] - Re: ERM to Entity relationship problem
by te-bachi
Second approach:
Same problem here: mappedBy reference an unknown target entity property
Exception:
| org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: gis.audit.entity.AuditSearchAssignEntity.criteriaId in gis.audit.entity.AuditSearchCriteriaEntity.auditSearchAssignEntities
| at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:506)
| at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:471)
| at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:43)
| at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1054)
| at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:296)
| at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1039)
| at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1211)
| at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:154)
| at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:847)
| at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:385)
| at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:126)
| at org.jboss.ejb3.entity.PersistenceUnitDeployment.start(PersistenceUnitDeployment.java:264)
| [...]
|
Assign PK:
| public class AuditSearchAssignPK implements Serializable {
| private BigInteger criteriaId;
| private BigInteger templateId;
|
| public AuditSearchAssignPK() {
| //
| }
|
| public AuditSearchAssignPK(BigInteger criteriaId, BigInteger templateId) {
| this.criteriaId = criteriaId;
| this.templateId = templateId;
| }
|
| public BigInteger getCriteriaId() {
| return criteriaId;
| }
|
| public void setCriteriaId(BigInteger criteriaId) {
| this.criteriaId = criteriaId;
| }
|
| public BigInteger getTemplateId() {
| return templateId;
| }
|
| public void setTemplateId(BigInteger templateId) {
| this.templateId = templateId;
| }
|
| public boolean equals(Object obj) {
| if (this == obj) return true;
| if (obj == null || getClass() != obj.getClass()) return false;
|
| AuditSearchAssignPK that = (AuditSearchAssignPK) obj;
|
| if (criteriaId != null ? !criteriaId.equals(that.criteriaId) : that.criteriaId != null) return false;
| if (templateId != null ? !templateId.equals(that.templateId) : that.templateId != null) return false;
|
| return true;
| }
|
| public int hashCode() {
| return criteriaId.hashCode() + templateId.hashCode();
| }
| }
|
Assign Entity:
| @Entity(name = "AuditSearchAssignEntity")
| @Table(schema = "UGIS1004", name = "GIS_T_AUDIT_SEARCH_ASSIGN")
| @IdClass(AuditSearchAssignPK.class)
| public class AuditSearchAssignEntity {
| private BigInteger criteriaOrder;
| private BigInteger isSpecific;
| private AuditSearchCriteriaEntity criteriaId;
| private AuditSearchTemplateEntity templateId;
|
| @Id
| @ManyToOne
| @JoinColumn(name = "CRITERIA_ID", referencedColumnName = "CRITERIA_ID", nullable = false)
| public AuditSearchCriteriaEntity getCriteriaId() {
| return criteriaId;
| }
|
| public void setCriteriaId(AuditSearchCriteriaEntity criteriaId) {
| this.criteriaId = criteriaId;
| }
|
| @Id
| @ManyToOne
| @JoinColumn(name = "TEMPLATE_ID", referencedColumnName = "TEMPLATE_ID", nullable = false)
| public AuditSearchTemplateEntity getTemplateId() {
| return templateId;
| }
|
| public void setTemplateId(AuditSearchTemplateEntity templateId) {
| this.templateId = templateId;
| }
|
| @Column(name = "CRITERIA_ORDER", nullable = false, length = 4)
| public BigInteger getCriteriaOrder() {
| return criteriaOrder;
| }
|
| public void setCriteriaOrder(BigInteger criteriaOrder) {
| this.criteriaOrder = criteriaOrder;
| }
|
| @Column(name = "IS_SPECIFIC", nullable = false, length = 1)
| public BigInteger getIsSpecific() {
| return isSpecific;
| }
|
| public void setIsSpecific(BigInteger specific) {
| isSpecific = specific;
| }
| }
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4006783#4006783
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4006783
19 years, 2 months
[EJB 3.0] - Re: ERM to Entity relationship problem
by te-bachi
First approach:
Exception:
| org.hibernate.AnnotationException: No identifier specified for entity: gis.audit.entity.AuditSearchAssignEntity
| at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:626)
| at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:452)
| at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:268)
| at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1039)
| at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1211)
| at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:154)
| at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:847)
| at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:385)
| at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:126)
| at org.jboss.ejb3.entity.PersistenceUnitDeployment.start(PersistenceUnitDeployment.java:264)
| [...]
|
Assign Entity:
| @Entity(name = "AuditSearchAssignEntity")
| @Table(schema = "UGIS1004", name = "GIS_T_AUDIT_SEARCH_ASSIGN")
| public class AuditSearchAssignEntity {
| private BigInteger criteriaOrder;
| private BigInteger isSpecific;
| private AuditSearchCriteriaEntity criteriaId;
| private AuditSearchTemplateEntity templateId;
|
| @ManyToOne
| @JoinColumn(name = "CRITERIA_ID", referencedColumnName = "CRITERIA_ID", nullable = false)
| public AuditSearchCriteriaEntity getCriteriaId() {
| return criteriaId;
| }
|
| public void setCriteriaId(AuditSearchCriteriaEntity criteriaId) {
| this.criteriaId = criteriaId;
| }
|
| @ManyToOne
| @JoinColumn(name = "TEMPLATE_ID", referencedColumnName = "TEMPLATE_ID", nullable = false)
| public AuditSearchTemplateEntity getTemplateId() {
| return templateId;
| }
|
| public void setTemplateId(AuditSearchTemplateEntity templateId) {
| this.templateId = templateId;
| }
|
| @Column(name = "CRITERIA_ORDER", nullable = false, length = 4)
| public BigInteger getCriteriaOrder() {
| return criteriaOrder;
| }
|
| public void setCriteriaOrder(BigInteger criteriaOrder) {
| this.criteriaOrder = criteriaOrder;
| }
|
| @Column(name = "IS_SPECIFIC", nullable = false, length = 1)
| public BigInteger getIsSpecific() {
| return isSpecific;
| }
|
| public void setIsSpecific(BigInteger specific) {
| isSpecific = specific;
| }
| }
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4006781#4006781
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4006781
19 years, 2 months
[EJB 3.0] - ERM to Entity relationship problem
by te-bachi
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
19 years, 2 months