-->
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: CollectionOfElements not persisting
PostPosted: Sun Dec 28, 2008 11:04 pm 
Regular
Regular

Joined: Sun Sep 25, 2005 11:35 pm
Posts: 57
I am trying to use the @CollectionOfElements annotation to save a set of value types along with my entity. Unfortunately, the entity is persisting but the value types are not. Can someone help me figure this out?

My entity class Account is shown below:

Code:
@Entity
public class Account implements Serializable {
    ...
    private Set<AccountParty> accountParties = new HashSet<AccountParty>();

    @CollectionOfElements(targetElement = AccountParty.class)
    @JoinTable(name = "Account_AccountParties",
        joinColumns = @JoinColumn(name = "account_id"))
    public Set<AccountParty> getAccountParties() {
        return accountParties;
    }

    public void setAccountParties(Set<AccountParty> accountParties) {
        this.accountParties = accountParties;
    }

    public void addAccountParty(AccountParty accountParty) {
        accountParties.add(accountParty);
    }
}


The value type AccountParty is shown below:

Code:
@Embeddable
public class AccountParty implements Serializable {
    private Party party;
    private AccountRole role;

    @ManyToOne(targetEntity=Party.class)
    public Party getParty() {
        return party;
    }
    public void setParty(Party party) {
        this.party = party;
    }

    public AccountRole getRole() {
        return role;
    }
    public void setRole(AccountRole role) {
        this.role = role;
    }
}


Finally, here's the code that persists an account with an AccountParty:

Code:
    public void createAccount(Party owner) {
        Account account = new Account();
        account.addAccountParty(
            new AccountParty(owner, AccountRole.owner));
        entityManager.persist(account);
    }


What am I doing wrong?

Thanks.
Naresh


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.