-->
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: Primary Constraint errors
PostPosted: Mon May 03, 2010 4:35 pm 
Newbie

Joined: Thu Jan 29, 2009 8:49 pm
Posts: 5
Hello,

I am having this weird issue that I am never been able to replicate but happens on the production server everyday.

We have a webpage where a user is able to edit their contact info and preferences. And the errors happens on save sometimes even when nothing is changed on the page.

Excerpt of the user pojo
Code:
@Entity
@Table(name= "MX_MASTER")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="MAST_MEMEX_INDORG", discriminatorType= DiscriminatorType.STRING)
public class Master extends ObjectEntity
{
@Id
    @GeneratedValue(generator = "oid")
    @GenericGenerator(name = "oid",strategy = "org.hibernate.id.IncrementGenerator")
    @Column(name="MAST_ID")
    protected Long id;

/**
     * A set of Address that belongs to this Master record. This variable maps
     * to MX_ADDRESS via hibernate.
     *
     */
    @OneToMany(mappedBy="owner")
    @Cascade(value={CascadeType.ALL, CascadeType.DELETE_ORPHAN})
    @Where(clause="CT_CODE='addr'")
    @OrderBy("id ASC")
    protected Set<Address> addresses = new TreeSet<Address>();

/**
     * A Set of Emails that belongs to this Master record. This variable maps to
     * MX_ADDRESS via hibernate.
     */
    @OneToMany(mappedBy="owner")
    @Cascade(value={CascadeType.ALL, CascadeType.DELETE_ORPHAN})
    @Where(clause="CT_CODE='email'")
    @OrderBy("id ASC")
    protected Set<Email> emails = new TreeSet<Email>();

/**
     * A set of Phone numbers that belongs to this Master record. This variable
     * maps to MX_ADDRESS via hibernate.
     */
    @OneToMany(mappedBy="owner")
    @Cascade(value={CascadeType.ALL, CascadeType.DELETE_ORPHAN})
    @Where(clause="CT_CODE='phone'")
    @OrderBy("id ASC")
    protected Set<Phone> phones = new TreeSet<Phone>();


/**
     * A set of category preferences that this Master record belongs to. This variable
     * maps to MX_LIST via hibernate.
     *     
     */
    @OneToMany(mappedBy="member")
    @Cascade(value={CascadeType.ALL, CascadeType.DELETE_ORPHAN})
    @Where(clause="LIST_CODE in(select L.LIST_CODE from MX_LIST L where L.LIST_TYPE='INT')")
    protected Set<ListMember> categories = new HashSet<ListMember>();
...

  /**
     * Method - Adds an address to the set of addresses
     *
     * @param Address
     * @return void
     */
    public void addAddress(Address address)
    {
       if (address != null)
       {
           address.setOwner(this);
           addContactInfo(address, this.addresses);
       }
    }

  /**
     * Method - adds a category to the master
     *
     * @param comm
     * @see committees
     */
    public boolean addCategory(List category, String writeIn) throws TooManyCategoryException
    {
          if (isCategoryMember(category))
          return false;
       ListMember lm = new ListMember(category, this);
       lm.setLastUpdateDate(new Date());
       if(writeIn != null)
           lm.setWriteIn(writeIn);
       return addCategory(lm);
    }

  /**
     * Method - Adds a contact info (Phone, Address, Url, Fax or Email) to their
     * respective set
     *
     * @param <T>
     * @param info
     * @param infos
     */
   
    protected <T extends ContactInfo> void addContactInfo(T info, Set<T> infos)
    {
       infos.add(info);
       if ((new Boolean(true)).equals(info.getPreferred()) || infos.size() == 1)
           setPreferredContactInfo(info, infos);       
    }


}


Excerpt if the parent contact info pojo from which other types like addresses, emails etc are derived from
Code:
@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="CT_CODE",  discriminatorType = DiscriminatorType.STRING)
@Table(name= "MX_ADDRESS")
public class ContactInfo extends ObjectEntity
{
/**
     * This variable maps to MX_ADDRESS.ADDR_ID via hibernate.
     */
    @Id
    @GeneratedValue(generator = "oid")
    @GenericGenerator(name = "oid",strategy = "org.hibernate.id.IncrementGenerator")
    @Column(name="ADDR_ID")
    protected Long id;

...}




Address and email look basically the same. so i have just added the mapping for the user many to one
Excerpt of Address and email pojo
Code:
@Entity
@DiscriminatorValue("addr")
public class Address extends ContactInfo
{

/**
     * This variable maps to MX_ADDRESS.MAST_ID via hibernate.
     */
    @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="MAST_ID")
    private Master owner;



Excerpt of Category preference pojo
Code:
@Entity
@Table(name= "MX_LIST_MEMBERSHIP")
public class ListMember extends ObjectEntity
{
@Id
    @GeneratedValue(generator = "oid")
    @GenericGenerator(name = "oid",strategy = "org.hibernate.id.IncrementGenerator")
    @Column(name="LM_ID")
    private Long id;


/**
     * This variable maps to MX_LIST_MEMBERSHIP.MAST_ID via hibernate.
     */
    @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="MAST_ID")
    private Master member;

}



Now i add/remove the addresses, emails, categories, etc. to the set directly in the users record and then save the user record. The exception is thrown on primary keys of MX_ADDRESS or MX_LIST_MEMBERSHIP tables.

Does anyone have any ideas what could cause these errors ???

~s.


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.