-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: How to map class that has field of type @Embeddable
PostPosted: Wed Sep 01, 2010 10:50 pm 
Newbie

Joined: Wed Sep 01, 2010 10:40 pm
Posts: 6
Location: Washington, D.C.
I have a class called Organization. This Organization class has 4 fields that are of type EPhoneEntry. This EPhoneEntry class has an annotation above the class declaration of @Embeddable. Anyone have an example of how to create the hbm.XML mapping file for a class similar to my organization class? My problem is when I run a piece of HQL within the "HQL Console" in the "IntelliJ IDEA" IDE it returns this error:

hql> from AdminValue
java.lang.RuntimeException: org.hibernate.MappingException: Repeated column in mapping for entity: com.bah.englink.ejb.Organization column: phoneType_ID (should be mapped with insert="false" update="false")
at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:652)
at org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:674)
at org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:670)
at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:696)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:450)
at org.hibernate.mapping.RootClass.validate(RootClass.java:192)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1108)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1293)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)

neither the Organization or the EPhoneEntry class contain a field (phoneType_ID) that is mentioned in the above error but I'm quessing that this problem stems from me mapping the Organization class wrong.

Code:
public class Organization implements Serializable
{
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name="ID")
    private Long id;

    @Embedded
    @NotNull
    @AttributeOverrides( {
        @AttributeOverride(name="phoneType", column = @Column(name="SAT_PHONE_ID_TYPE_AV", nullable = true) ),
        @AttributeOverride(name="partyCode", column = @Column(name="SAT_PHONE_PARTY_CODE", nullable = true) ),
        @AttributeOverride(name="phoneNumber", column = @Column(name="SAT_PHONE_NUMBER", nullable = true) ),
        @AttributeOverride(name="international", column = @Column(name="SAT_PHONE_IS_INTL_BIT", nullable = true) )} )
    private EPhoneEntry satellitePhone = new EPhoneEntry();

    @Embedded
    @NotNull
    @AttributeOverrides( {
        @AttributeOverride(name="phoneType", column = @Column(name="SECURE_PHONE_ID_TYPE_AV", nullable = true) ),
        @AttributeOverride(name="partyCode", column = @Column(name="SECURE_PHONE_PARTY_CODE", nullable = true) ),
        @AttributeOverride(name="phoneNumber", column = @Column(name="SECURE_PHONE_NUMBER", nullable = true) ),
        @AttributeOverride(name="international", column = @Column(name="SECURE_PHONE_IS_INTL_BIT", nullable = true) )} )
    private EPhoneEntry securePhone = new EPhoneEntry();
   
    @Embedded
    @NotNull
    @AttributeOverrides( {
        @AttributeOverride(name="phoneType", column = @Column(name="FAX_ID_TYPE_AV", nullable = true) ),
        @AttributeOverride(name="partyCode", column = @Column(name="FAX_PARTY_CODE", nullable = true) ),
        @AttributeOverride(name="phoneNumber", column = @Column(name="FAX_NUMBER", nullable = true) ),
        @AttributeOverride(name="international", column = @Column(name="FAX_IS_INTL_BIT", nullable = true) )} )
    private EPhoneEntry fax = new EPhoneEntry();
   
    @Embedded
    @NotNull
    @AttributeOverrides( {
        @AttributeOverride(name="phoneType", column = @Column(name="SECURE_FAX_ID_TYPE_AV", nullable = true) ),
        @AttributeOverride(name="partyCode", column = @Column(name="SECURE_FAX_PARTY_CODE", nullable = true) ),
        @AttributeOverride(name="phoneNumber", column = @Column(name="SECURE_FAX_NUMBER", nullable = true) ),
        @AttributeOverride(name="international", column = @Column(name="SECURE_FAX_IS_INTL_BIT", nullable = true) )} )
    private EPhoneEntry secureFax = new EPhoneEntry();
   
    /** The EOC phone number of the organization **/
    @Embedded
    @NotNull
    @AttributeOverrides( {
        @AttributeOverride(name="phoneType", column = @Column(name="EOC_PHONE_ID_TYPE_AV", nullable = true) ),
        @AttributeOverride(name="partyCode", column = @Column(name="EOC_PHONE_PARTY_CODE", nullable = true) ),
        @AttributeOverride(name="phoneNumber", column = @Column(name="EOC_PHONE_NUMBER", nullable = true) ),
        @AttributeOverride(name="international", column = @Column(name="EOC_PHONE_IS_INTL_BIT", nullable = true) )} )
    private EPhoneEntry eocPhone;


and this is the EPhoneEntry class:
Code:
package com.bah.englink.ejb.types;

import java.io.Serializable;
import javax.persistence.*;
import org.hibernate.annotations.AccessType;
import org.hibernate.annotations.Index;
import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;

import com.bah.englink.ejb.da.AdminValue;

@Embeddable
public class EPhoneEntry implements Serializable
{
        @OneToOne
        @JoinColumn(nullable = true)
        private AdminValue phoneType;
       
        private String partyCode;
       
        @Length(max=24)
        private String phoneNumber;
       
        @Column
        private boolean international = false;

        public EPhoneEntry() {
            setInternational(false);
        }
       
        public EPhoneEntry(boolean international) {
            setInternational(international);
        }
       
        public EPhoneEntry(AdminValue phoneType) {
            setPhoneType(phoneType);
        }
       
        public EPhoneEntry(AdminValue phoneType, boolean international) {
            setPhoneType(phoneType);
            setInternational(international);
        }
           
        public AdminValue getPhoneType() {
            return phoneType;
        }

        public void setPhoneType(AdminValue phoneType) {
            this.phoneType = phoneType;
        }

        public String getPhoneNumber() {
            return phoneNumber;
        }

        public void setPhoneNumber(String phoneNumber) {
            this.phoneNumber = phoneNumber;
        }
     }


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.