Hibernate version:3.2.0
Entity:
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Table(name = "partner", catalog = "partner", uniqueConstraints = {})
public class PartnerPartner extends PartnerResource
{
/**
*
*/
private static final long serialVersionUID = 1L;
private Set<PartnerSite> sites = new HashSet<PartnerSite>( 0 );
private PartnerOrganization organization;
private PartnerPartnerContact partnerContact;
private PartnerPartnerPayment partnerPayment;
private Set<PartnerCategory> categories = new HashSet<PartnerCategory>( 0 );
private Set<PartnerPartnerContactUs> partnerContactUss = new HashSet<PartnerPartnerContactUs>( 0 );
private Set<PartnerPartnerRate> partnerRates = new HashSet<PartnerPartnerRate>( 0 );
// Constructors
public PartnerPartner()
{
super();
}
public PartnerPartner( Integer id )
{
super( id );
}
public PartnerPartner( String name )
{
super( name );
}
@ManyToMany(cascade = { CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH }, fetch = FetchType.LAZY)
@JoinTable(name = "partner_site", catalog = "partner", joinColumns = { @JoinColumn(name = "partner_id") }, inverseJoinColumns = @JoinColumn(name = "site_id"))
public Set<PartnerSite> getSites()
{
return sites;
}
public void setSites( Set<PartnerSite> sites )
{
this.sites = sites;
}
@OneToOne(cascade = { CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH }, fetch = FetchType.EAGER)
@JoinColumn(name = "organization_id", unique = false, nullable = false, insertable = true, updatable = true)
public PartnerOrganization getOrganization()
{
return organization;
}
public void setOrganization( PartnerOrganization organization )
{
this.organization = organization;
}
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinTable(name = "category_partner", joinColumns = { @JoinColumn(name = "partner_id") }, inverseJoinColumns = @JoinColumn(name = "category_id"))
public Set<PartnerCategory> getCategories()
{
return categories;
}
public void setCategories( Set<PartnerCategory> categories )
{
this.categories = categories;
}
@OneToOne(cascade = { CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH }, fetch = FetchType.LAZY, optional = true)
@PrimaryKeyJoinColumn
public PartnerPartnerContact getPartnerContact()
{
return this.partnerContact;
}
public void setPartnerContact( PartnerPartnerContact partnerContact )
{
this.partnerContact = partnerContact;
}
@OneToOne(cascade = { CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH }, fetch = FetchType.LAZY, optional = true)
@PrimaryKeyJoinColumn
public PartnerPartnerPayment getPartnerPayment()
{
return partnerPayment;
}
public void setPartnerPayment( PartnerPartnerPayment partnerPayment )
{
this.partnerPayment = partnerPayment;
}
@OneToMany(cascade = { CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH }, fetch = FetchType.LAZY, mappedBy = "partner")
public Set<PartnerPartnerContactUs> getPartnerContactUss()
{
return partnerContactUss;
}
public void setPartnerContactUss( Set<PartnerPartnerContactUs> partnerContactUss )
{
this.partnerContactUss = partnerContactUss;
}
@OneToMany(mappedBy = "partner", cascade = { CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH }, fetch = FetchType.LAZY)
public Set<PartnerPartnerRate> getPartnerRates()
{
return partnerRates;
}
public void setPartnerRates( Set<PartnerPartnerRate> partnerRates )
{
this.partnerRates = partnerRates;
}
@Override
public boolean equals( Object other )
{
if( super.equals( other ) )
return true;
if( other instanceof PartnerPartner )
{
}
return false;
}
@Override
public String toString()
{
return "Partner : Id[" + getId() + "], Name[" + getName() + "], Uri[" + getUri() + "], Status[" + getStatus() + "]";
}
}
Entity Manager code:
(em is EntityManager, et is EntityTransaction)
et = em.getTransaction();
et.begin();
partner = em.merge( partner );
et.commit();
Name and version of the database you are using: MySql 5.0.22
Hi,
I have a bean representing a "PARTNER" table with maps to many other tables. a couple of those relations are many-to-many.
When ever I want to update some data in the bean, unless I populate the many-to-many collections, the merge() assumes that the empty collection means no related rows and delete the data in the relation table.
This is a problem since populating some of this collections can be quite large and time consuming. so... sometimes I need to update the relations and sometimes I don't...
further more, sometimes I only want to add one relational row, and again, I need to load the entire collection.
Is there a way to inform hibernate that I do NOT want to cascade the update to null collections?
Is there any smart way to manipulate many-to-many collections without loading the entire collection?
Thanks,
oryanay
|