Author: epbernard
Date: 2007-10-29 19:27:09 -0400 (Mon, 29 Oct 2007)
New Revision: 14158
Added:
search/trunk/src/test/org/hibernate/search/test/embedded/doubleinsert/
search/trunk/src/test/org/hibernate/search/test/embedded/doubleinsert/Address.java
search/trunk/src/test/org/hibernate/search/test/embedded/doubleinsert/BusinessContact.java
search/trunk/src/test/org/hibernate/search/test/embedded/doubleinsert/Contact.java
search/trunk/src/test/org/hibernate/search/test/embedded/doubleinsert/DoubleInsertEmbeddedTest.java
search/trunk/src/test/org/hibernate/search/test/embedded/doubleinsert/PersonalContact.java
search/trunk/src/test/org/hibernate/search/test/embedded/doubleinsert/Phone.java
Log:
HSEARCH-124 Test for the double insert issue (not reproduced)
Added: search/trunk/src/test/org/hibernate/search/test/embedded/doubleinsert/Address.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/embedded/doubleinsert/Address.java
(rev 0)
+++
search/trunk/src/test/org/hibernate/search/test/embedded/doubleinsert/Address.java 2007-10-29
23:27:09 UTC (rev 14158)
@@ -0,0 +1,250 @@
+package org.hibernate.search.test.embedded.doubleinsert;
+
+import java.io.Serializable;
+import java.util.Date;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.Table;
+
+import org.hibernate.annotations.Type;
+import org.hibernate.search.annotations.DocumentId;
+import org.hibernate.search.annotations.Field;
+import org.hibernate.search.annotations.Index;
+import org.hibernate.search.annotations.Indexed;
+import org.hibernate.search.annotations.IndexedEmbedded;
+import org.hibernate.search.annotations.Store;
+
+@Entity
+@Indexed
+@Table(name="T_ADDRESS")
+public class Address implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+
+ @Id @GeneratedValue(strategy=GenerationType.AUTO)
+ @Column(name="A_ADDRESS_ID")
+ @DocumentId
+ private long id;
+
+ @Column(name="A_ADDRESS1")
+ @Field(index=Index.TOKENIZED, store=Store.YES)
+ private String address1;
+
+ @Column(name="A_ADDRESS2")
+ @Field(index=Index.TOKENIZED, store=Store.YES)
+ private String address2;
+
+ @Column(name="A_TOWN")
+ @Field(index=Index.TOKENIZED, store=Store.YES)
+ private String town;
+
+ @Column(name="A_COUNTY")
+ @Field(index=Index.TOKENIZED, store=Store.YES)
+ private String county;
+
+ @Column(name="A_COUNTRY")
+ @Field(index=Index.TOKENIZED, store=Store.YES)
+ private String country;
+
+ @Column(name="A_POSTCODE")
+ @Field(index=Index.TOKENIZED, store=Store.YES)
+ private String postcode;
+
+ @Column(name="A_ACTIVE")
+ @Type(type="boolean")
+ private boolean active;
+
+ @Column(name="A_CREATEDON")
+ @Type(type="java.util.Date")
+ private Date createdOn;
+
+ @Column(name="A_LASTUPDATEDON")
+ @Type(type="java.util.Date")
+ private Date lastUpdatedOn;
+
+ @ManyToOne
+ @JoinColumn(name="C_CONTACT_ID")
+ @IndexedEmbedded
+ private Contact contact;
+
+ public Address(String address1, String address2, String town,
+ String county, String country, String postcode, boolean active, Contact contact) {
+ super();
+ this.address1 = address1;
+ this.address2 = address2;
+ this.town = town;
+ this.county = county;
+ this.country = country;
+ this.postcode = postcode;
+ this.active = active;
+ this.contact = contact;
+ }
+
+ public Address() {
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public String getAddress1() {
+ return address1;
+ }
+
+ public void setAddress1(String address1) {
+ this.address1 = address1;
+ }
+
+ public String getAddress2() {
+ if (null == this.address2 || "".equals(this.address2)) {
+ return "N/A";
+ }
+ return address2;
+ }
+
+ public void setAddress2(String address2) {
+ this.address2 = address2;
+ }
+
+ public String getTown() {
+ return town;
+ }
+
+ public void setTown(String town) {
+ this.town = town;
+ }
+
+ public String getCounty() {
+ if (null == this.county || "".equals(this.county)) {
+ return "N/A";
+ }
+ return county;
+ }
+
+ public void setCounty(String county) {
+ this.county = county;
+ }
+
+ public String getCountry() {
+ return country;
+ }
+
+ public void setCountry(String country) {
+ this.country = country;
+ }
+
+ public String getPostcode() {
+ return postcode;
+ }
+
+ public void setPostcode(String postcode) {
+ this.postcode = postcode;
+ }
+
+ public boolean isActive() {
+ return active;
+ }
+
+ public void setActive(boolean active) {
+ this.active = active;
+ }
+
+
+ public Date getCreatedOn() {
+ return createdOn;
+ }
+
+ public void setCreatedOn(Date createdOn) {
+ this.createdOn = createdOn;
+ }
+
+ public Date getLastUpdatedOn() {
+ return lastUpdatedOn;
+ }
+
+ public void setLastUpdatedOn(Date lastUpdatedOn) {
+ this.lastUpdatedOn = lastUpdatedOn;
+ }
+
+
+
+ public Contact getContact() {
+ return contact;
+ }
+
+ public void setContact(Contact contact) {
+ this.contact = contact;
+ }
+
+ public boolean equals(Object object) {
+ if (!(object instanceof Address)) {
+ return false;
+ }
+ Address that = (Address)object;
+ if ( ! equals(this.getAddress1(), that.getAddress1() ) ) return false;
+ if ( ! equals(this.getAddress2(), that.getAddress2() ) ) return false;
+ if ( ! equals(this.getCounty(), that.getCounty() ) ) return false;
+ if ( ! equals(this.getTown(), that.getTown() ) ) return false;
+ if ( ! equals(this.getPostcode(), that.getPostcode() ) ) return false;
+ if ( ! equals(this.getContact(), that.getContact() ) ) return false;
+ return true;
+// EqualsBuilder equalsBuilder = new EqualsBuilder();
+// return equalsBuilder.append(new Object[]{this.getAddress1(), this.getAddress2(),
this.getCounty(), this.getTown(), this.getPostcode(), this.contact}, new
Object[]{address.getAddress1(), address.getAddress2(), address.getCounty(),
address.getTown(), address.getPostcode(), address.getContact()}).isEquals();
+ }
+
+ private boolean equals(Object o1, Object o2) {
+ if ( o1 == o2 ) return true;
+ if ( o1 == null || o2 == null ) return false;
+ return o1.equals( o1.equals( o2 ) );
+ }
+
+ private int hashCode(Object o) {
+ return o == null ? 0 : o.hashCode();
+ }
+
+
+ public int hashCode() {
+ int a = 13;
+ a = a*23 + hashCode( this.getAddress1());
+ a = a*23 + hashCode( this.getAddress2());
+ a = a*23 + hashCode( this.getCounty());
+ a = a*23 + hashCode( this.getTown());
+ a = a*23 + hashCode( this.getPostcode());
+ a = a*23 + hashCode( this.getContact());
+ return a;
+// return new HashCodeBuilder().append(new Object[]{this.getAddress1(),
this.getAddress2(), this.getCounty(), this.getTown(), this.getPostcode(),
this.getContact()}).hashCode();
+ }
+
+
+ public String toString() {
+ StringBuffer buf = new StringBuffer();
+ displayAddress(buf, this);
+ return buf.toString();
+ }
+ private void displayAddress(StringBuffer buf, Address address) {
+// buf.append(Constants.TAB + Constants.TAB + "Address 1: " +
address.getAddress1() + Constants.NEW_LINE);
+// buf.append(Constants.TAB + Constants.TAB +"Address 2: " +
address.getAddress2() + Constants.NEW_LINE);
+// buf.append(Constants.TAB + Constants.TAB +"Town: " + address.getTown() +
Constants.NEW_LINE);
+// buf.append(Constants.TAB + Constants.TAB +"County: " + address.getCounty()
+ Constants.NEW_LINE);
+// buf.append(Constants.TAB + Constants.TAB +"Postcode: " +
address.getPostcode() + Constants.NEW_LINE);
+// buf.append(Constants.TAB + Constants.TAB +"Country: " +
address.getCountry() + Constants.NEW_LINE);
+// buf.append(Constants.TAB + Constants.TAB +"Is current: " +
(address.isActive()? "Yes" : "No") + Constants.NEW_LINE);
+// buf.append(Constants.NEW_LINE);
+ }
+
+ public boolean isValidPostcode() {
+
+ return false;
+ }
+
+}
Added:
search/trunk/src/test/org/hibernate/search/test/embedded/doubleinsert/BusinessContact.java
===================================================================
---
search/trunk/src/test/org/hibernate/search/test/embedded/doubleinsert/BusinessContact.java
(rev 0)
+++
search/trunk/src/test/org/hibernate/search/test/embedded/doubleinsert/BusinessContact.java 2007-10-29
23:27:09 UTC (rev 14158)
@@ -0,0 +1,70 @@
+package org.hibernate.search.test.embedded.doubleinsert;
+
+import javax.persistence.Column;
+import javax.persistence.DiscriminatorValue;
+import javax.persistence.Entity;
+
+import org.hibernate.search.annotations.Field;
+import org.hibernate.search.annotations.Index;
+import org.hibernate.search.annotations.Indexed;
+import org.hibernate.search.annotations.Store;
+
+@Entity
+@DiscriminatorValue("BusinessContact")
+@Indexed
+public class BusinessContact extends Contact {
+
+ @Column(name="P_BUSINESSNAME")
+ @Field(index=Index.TOKENIZED, store=Store.YES)
+ private String businessName;
+
+ @Column(name="P_BUSINESSURL")
+ @Field(index=Index.TOKENIZED, store=Store.YES)
+ private String url;
+
+ public BusinessContact() {
+ }
+
+ public String getBusinessName() {
+ return businessName;
+ }
+
+ public void setBusinessName(String businessName) {
+ this.businessName = businessName;
+ }
+
+ public String getUrl() {
+ if (null == this.url || "".equals(this.url)) {
+ return "Not provided";
+ }
+ return url;
+ }
+
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+// public boolean equals(Object object) {
+// if (!(object instanceof BusinessContact)) {
+// return false;
+// }
+// BusinessContact businessContact = (BusinessContact)object;
+// return new EqualsBuilder().append(new Object[]{this.getId(), this.getBusinessName(),
this.getUrl()}, new Object[]{businessContact.getId(), businessContact.getBusinessName(),
businessContact.getUrl()}).isEquals();
+// }
+//
+// public int hashCode() {
+// return new HashCodeBuilder().append(new Object[]{new Long(this.getId()),
this.getBusinessName(), this.getUrl()}).toHashCode();
+// }
+// public String toString() {
+// StringBuffer buf = new StringBuffer();
+// buf.append("Business Name: " + this.getBusinessName() +
Constants.NEW_LINE);
+// buf.append("Business Url: " + this.getUrl() + Constants.NEW_LINE);
+// buf.append("Email: " + this.getEmail() + Constants.NEW_LINE);
+// super.displayPhonesAndAddresses(buf);
+// return buf.toString();
+// }
+
+
+
+}
Added: search/trunk/src/test/org/hibernate/search/test/embedded/doubleinsert/Contact.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/embedded/doubleinsert/Contact.java
(rev 0)
+++
search/trunk/src/test/org/hibernate/search/test/embedded/doubleinsert/Contact.java 2007-10-29
23:27:09 UTC (rev 14158)
@@ -0,0 +1,221 @@
+package org.hibernate.search.test.embedded.doubleinsert;
+
+import java.io.Serializable;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.DiscriminatorColumn;
+import javax.persistence.DiscriminatorValue;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.OneToMany;
+import javax.persistence.Table;
+
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections.Predicate;
+import org.apache.log4j.Logger;
+import org.hibernate.annotations.Type;
+import org.hibernate.search.annotations.ContainedIn;
+import org.hibernate.search.annotations.DocumentId;
+import org.hibernate.search.annotations.Field;
+import org.hibernate.search.annotations.Index;
+import org.hibernate.search.annotations.Indexed;
+import org.hibernate.search.annotations.Store;
+
+@Entity
+@Table(name="T_CONTACT")
+(a)Inheritance(strategy=InheritanceType.SINGLE_TABLE)
+@DiscriminatorValue("Contact")
+@DiscriminatorColumn(name="contactType",discriminatorType=javax.persistence.DiscriminatorType.STRING)
+@Indexed
+public class Contact implements Serializable {
+
+ private static Logger logger = Logger.getLogger(Contact.class);
+
+ private static final long serialVersionUID = 1L;
+
+ @Id @GeneratedValue(strategy=GenerationType.AUTO)
+ @Column(name="C_CONTACT_ID")
+ @DocumentId
+ private long id;
+
+ @Column(name="C_EMAIL")
+ @Field(index=Index.TOKENIZED, store=Store.YES)
+ private String email;
+
+ @Column(name="C_CREATEDON")
+ @Type(type="java.util.Date")
+ private Date createdOn;
+
+ @Column(name="C_LASTUPDATEDON")
+ @Type(type="java.util.Date")
+ private Date lastUpdatedOn;
+
+ @ContainedIn
+ @OneToMany( cascade = { CascadeType.ALL}, fetch=FetchType.EAGER)
+ @Type(type="java.util.Set")
+ private Set<Address> addresses;
+
+ @ContainedIn
+ @OneToMany(cascade = { CascadeType.ALL}, fetch=FetchType.EAGER)
+ @Type(type="java.util.Set")
+ private Set<Phone> phoneNumbers;
+
+ @Column(name="C_NOTES")
+ private String notes;
+
+ public Contact() {
+ }
+
+ public long getId() {
+ return id;
+ }
+ public void setId(long id) {
+ this.id = id;
+ }
+ public String getEmail() {
+ if (null == this.email || "".equals(this.email)) {
+ return "N/A";
+ }
+ return email;
+ }
+ public void setEmail(String email) {
+ this.email = email;
+ }
+ public Date getCreatedOn() {
+ return createdOn;
+ }
+ public void setCreatedOn(Date createdOn) {
+ this.createdOn = createdOn;
+ }
+ public Date getLastUpdatedOn() {
+ return lastUpdatedOn;
+ }
+ public void setLastUpdatedOn(Date lastUpdatedOn) {
+ this.lastUpdatedOn = lastUpdatedOn;
+ }
+ public Set<Address> getAddresses() {
+ return addresses;
+ }
+ public void setAddresses(Set<Address> addresses) {
+ this.addresses = addresses;
+ }
+ public Set<Phone> getPhoneNumbers() {
+ return phoneNumbers;
+ }
+ public void setPhoneNumbers(Set<Phone> phoneNumbers) {
+ this.phoneNumbers = phoneNumbers;
+ }
+
+
+ public String getNotes() {
+ return notes;
+ }
+
+ public void setNotes(String notes) {
+ this.notes = notes;
+ }
+
+ public void addAddressToContact(Address address) {
+ if (address == null) {
+ throw new IllegalArgumentException("Address cannot be null");
+ }
+ if (addresses == null) {
+ addresses = new HashSet<Address>();
+ }
+ address.setContact(this);
+ addresses.add(address);
+ }
+
+
+ public void addPhoneToContact(Phone phone) {
+ if (phone == null) {
+ throw new IllegalArgumentException("Phone cannot be null");
+ }
+ if (phoneNumbers == null) {
+ phoneNumbers = new HashSet<Phone>();
+ }
+ phone.setContact(this);
+ phoneNumbers.add(phone);
+ }
+
+
+ public void removePhoneFromContact(Phone phone) {
+ if (phone == null) {
+ throw new IllegalArgumentException("Phone cannot be null");
+ }
+ if (this.phoneNumbers.contains(phone)) {
+ this.phoneNumbers.remove(phone);
+ }
+ }
+
+ public void removeAddressFromContact(Address address) {
+ if (address == null) {
+ throw new IllegalArgumentException("Address cannot be null");
+ }
+ if (this.addresses.contains(address)) {
+ this.addresses.remove(address);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ protected List<Phone> filterPhoneNumbersByType(final String phoneType) {
+// Assert.notNull(phoneType, "Phone type cannot be null");
+// Assert.hasText(phoneType, "Phone type cannot be empty");
+ return (List<Phone>)CollectionUtils.select(this.phoneNumbers, new Predicate()
{
+ public boolean evaluate(Object object) {
+ Phone phone = (Phone)object;
+ return phoneType.equals(phone.getType());
+ }
+ });
+ }
+
+
+ @SuppressWarnings("unchecked")
+ protected List<Address> showActiveAddresses() {
+ return (List<Address>) CollectionUtils.select(this.addresses,new Predicate()
{
+ public boolean evaluate(Object object) {
+ Address address = (Address)object;
+ return address.isActive();
+ }
+ });
+ }
+
+ @SuppressWarnings("unchecked")
+ protected List<Address> showInactiveAddresses() {
+ return (List<Address>) CollectionUtils.select(this.addresses, new Predicate()
{
+ public boolean evaluate(Object object) {
+ Address address = (Address)object;
+ return !address.isActive();
+ }
+ });
+ }
+
+ protected void displayPhonesAndAddresses(StringBuffer buf) {
+// buf.append(Constants.NEW_LINE);
+// buf.append("Phone Detail(s):" + Constants.NEW_LINE);
+// if (null != this.getPhoneNumbers() && 0 != this.getPhoneNumbers().size()) {
+// for (Phone phone: this.getPhoneNumbers()) {
+// buf.append(phone);
+// }
+// }
+// buf.append(Constants.NEW_LINE);
+// buf.append("Address Details:" + Constants.NEW_LINE );
+// if (null != this.getAddresses() && 0 != this.getAddresses().size()) {
+// for (Address address: this.getAddresses()) {
+// buf.append(address);
+// }
+// }
+ }
+
+
+}
Added:
search/trunk/src/test/org/hibernate/search/test/embedded/doubleinsert/DoubleInsertEmbeddedTest.java
===================================================================
---
search/trunk/src/test/org/hibernate/search/test/embedded/doubleinsert/DoubleInsertEmbeddedTest.java
(rev 0)
+++
search/trunk/src/test/org/hibernate/search/test/embedded/doubleinsert/DoubleInsertEmbeddedTest.java 2007-10-29
23:27:09 UTC (rev 14158)
@@ -0,0 +1,90 @@
+//$
+package org.hibernate.search.test.embedded.doubleinsert;
+
+import java.util.Date;
+import java.io.File;
+
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.TermQuery;
+import org.apache.lucene.analysis.StopAnalyzer;
+import org.hibernate.Query;
+import org.hibernate.event.PostDeleteEventListener;
+import org.hibernate.event.PostUpdateEventListener;
+import org.hibernate.event.PostInsertEventListener;
+import org.hibernate.search.FullTextSession;
+import org.hibernate.search.Search;
+import org.hibernate.search.Environment;
+import org.hibernate.search.event.FullTextIndexEventListener;
+import org.hibernate.search.store.FSDirectoryProvider;
+import org.hibernate.search.test.SearchTestCase;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class DoubleInsertEmbeddedTest extends SearchTestCase {
+ public void testDoubleInsert() throws Exception {
+ Address address = new Address();
+ address.setAddress1( "TEST1" );
+ address.setAddress2( "N/A" );
+ address.setTown( "TEST TOWN" );
+ address.setCounty( "TEST COUNTY" );
+ address.setCountry( "UK" );
+ address.setPostcode( "XXXXXXX" );
+ address.setActive( true );
+ address.setCreatedOn( new Date() );
+ address.setLastUpdatedOn( new Date() );
+
+ Phone phone = new Phone();
+ phone.setNumber( "01273234122" );
+ phone.setType( "HOME" );
+ phone.setCreatedOn( new Date() );
+ phone.setLastUpdatedOn( new Date() );
+
+ PersonalContact contact = new PersonalContact();
+ contact.setFirstname( "Amin" );
+ contact.setSurname( "Mohammed-Coleman" );
+ contact.setEmail( "address(a)hotmail.com" );
+ contact.setDateOfBirth( new Date() );
+ contact.setNotifyBirthDay( false );
+ contact.setCreatedOn( new Date() );
+ contact.setLastUpdatedOn( new Date() );
+ contact.setNotes( "TEST" );
+ contact.addAddressToContact( address );
+ contact.addPhoneToContact( phone );
+
+ FullTextSession s = Search.createFullTextSession( openSession( ) );
+ s.getTransaction().begin();
+ s.save( contact);
+ s.getTransaction().commit();
+
+ s.close();
+
+ s = Search.createFullTextSession( openSession( ) );
+ s.getTransaction().begin();
+ Term term = new Term("county", "county");
+ TermQuery termQuery = new TermQuery( term );
+ Query query = s.createFullTextQuery( termQuery );
+ assertEquals( 1, query.list().size() );
+ contact = (PersonalContact) s.get( PersonalContact.class, contact.getId() );
+ contact.getPhoneNumbers().clear();
+ contact.getAddresses().clear();
+ s.flush();
+ s.clear();
+ s.createQuery( "delete " + Address.class.getName() ).executeUpdate();
+ s.createQuery( "delete " + Phone.class.getName() ).executeUpdate();
+ s.createQuery( "delete " + Contact.class.getName() ).executeUpdate();
+ s.getTransaction().commit();
+
+ s.close();
+ }
+
+ protected Class[] getMappings() {
+ return new Class[] {
+ Address.class,
+ Contact.class,
+ PersonalContact.class,
+ BusinessContact.class,
+ Phone.class
+ };
+ }
+}
Added:
search/trunk/src/test/org/hibernate/search/test/embedded/doubleinsert/PersonalContact.java
===================================================================
---
search/trunk/src/test/org/hibernate/search/test/embedded/doubleinsert/PersonalContact.java
(rev 0)
+++
search/trunk/src/test/org/hibernate/search/test/embedded/doubleinsert/PersonalContact.java 2007-10-29
23:27:09 UTC (rev 14158)
@@ -0,0 +1,159 @@
+package org.hibernate.search.test.embedded.doubleinsert;
+
+import java.util.Date;
+
+import javax.persistence.Column;
+import javax.persistence.DiscriminatorValue;
+import javax.persistence.Entity;
+
+import org.hibernate.annotations.Type;
+import org.hibernate.search.annotations.Field;
+import org.hibernate.search.annotations.Index;
+import org.hibernate.search.annotations.Indexed;
+import org.hibernate.search.annotations.Store;
+
+@Entity
+@DiscriminatorValue("PersonalContact")
+@Indexed
+public class PersonalContact extends Contact {
+ private static final long serialVersionUID = 1L;
+
+ @Column(name="P_FIRSTNAME")
+ @Field(index=Index.TOKENIZED, store=Store.YES)
+ private String firstname;
+
+ @Column(name="P_SURNAME")
+ @Field(index=Index.TOKENIZED, store=Store.YES)
+ private String surname;
+
+ @Column(name="P_DATEOFBIRTH")
+ @Type(type="java.util.Date")
+ private Date dateOfBirth;
+
+ @Column(name="P_NOTIFYBIRTHDAY")
+ @Type(type="boolean")
+ private boolean notifyBirthDay;
+
+ @Column(name="P_MYFACESURL")
+ @Field(index=Index.TOKENIZED, store=Store.YES)
+ private String myFacesUrl;
+
+ @Column(name="P_REMINDERCOUNT")
+ private int reminderCount;
+
+ @Column(name="P_REMINDERRESET")
+ @Type(type="boolean")
+ private boolean reset;
+
+
+ public PersonalContact() {
+ }
+
+ public String getFirstname() {
+ return firstname;
+ }
+ public void setFirstname(String firstname) {
+ this.firstname = firstname;
+ }
+ public String getSurname() {
+ return surname;
+ }
+ public void setSurname(String surname) {
+ this.surname = surname;
+ }
+ public Date getDateOfBirth() {
+ return dateOfBirth;
+ }
+ public void setDateOfBirth(Date dateOfBirth) {
+ this.dateOfBirth = dateOfBirth;
+ }
+
+ public boolean isNotifyBirthDay() {
+ return notifyBirthDay;
+ }
+
+ public void setNotifyBirthDay(boolean notifyBirthDay) {
+ this.notifyBirthDay = notifyBirthDay;
+ }
+
+
+ public String getMyFacesUrl() {
+ return myFacesUrl;
+ }
+
+ public void setMyFacesUrl(String myFacesUrl) {
+ this.myFacesUrl = myFacesUrl;
+ }
+
+
+
+ public int getReminderCount() {
+ return reminderCount;
+ }
+
+ public void setReminderCount(int reminderCount) {
+ this.reminderCount = reminderCount;
+ }
+
+
+ public boolean isReset() {
+ return reset;
+ }
+
+ public void setReset(boolean reset) {
+ this.reset = reset;
+ }
+
+ private boolean equals(Object o1, Object o2) {
+ if ( o1 == o2 ) return true;
+ if ( o1 == null || o2 == null ) return false;
+ return o1.equals( o1.equals( o2 ) );
+ }
+
+ private int hashCode(Object o) {
+ return o == null ? 0 : o.hashCode();
+ }
+
+ public boolean equals(Object object) {
+ if (!(object instanceof PersonalContact)) {
+ return false;
+ }
+ PersonalContact that = (PersonalContact)object;
+ if ( ! equals(this.getId(), that.getId() ) ) return false;
+ if ( ! equals(this.getFirstname(), that.getFirstname() ) ) return false;
+ if ( ! equals(this.getSurname(), that.getSurname() ) ) return false;
+ return true;
+ }
+
+ public int hashCode() {
+ int a = 13;
+ a = a*23 + hashCode( this.getId());
+ a = a*23 + hashCode( this.getFirstname());
+ a = a*23 + hashCode( this.getSurname());
+ return a;
+ }
+
+// public boolean equals(Object object) {
+// if (!(object instanceof PersonalContact)) {
+// return false;
+// }
+// PersonalContact personalContact = (PersonalContact)object;
+// return new EqualsBuilder().append(new Object[]{this.getId(), this.getFirstname(),
this.getSurname()}, new Object[]{personalContact.getId(), personalContact.getFirstname(),
personalContact.getSurname()}).isEquals();
+// }
+//
+// public int hashCode() {
+// return new HashCodeBuilder().append(new Object[]{new Long(this.getId()),
this.getFirstname(), this.getSurname()}).toHashCode();
+// }
+//
+// public String toString() {
+// StringBuffer buf = new StringBuffer();
+// buf.append("First Name: " + this.getFirstname()+ Constants.NEW_LINE);
+// buf.append("Surname: " + this.getSurname() + Constants.NEW_LINE);
+// buf.append("Email: " + this.getEmail() + Constants.NEW_LINE);
+// buf.append("Date of Birth: " + (null == this.getDateOfBirth() ? "Not
Provided" : this.getDateOfBirth()) + Constants.NEW_LINE);
+// displayPhonesAndAddresses(buf);
+// return buf.toString();
+// }
+
+
+}
Added: search/trunk/src/test/org/hibernate/search/test/embedded/doubleinsert/Phone.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/embedded/doubleinsert/Phone.java
(rev 0)
+++
search/trunk/src/test/org/hibernate/search/test/embedded/doubleinsert/Phone.java 2007-10-29
23:27:09 UTC (rev 14158)
@@ -0,0 +1,129 @@
+package org.hibernate.search.test.embedded.doubleinsert;
+
+import java.io.Serializable;
+import java.util.Date;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.Table;
+
+import org.hibernate.annotations.Type;
+import org.hibernate.search.annotations.DocumentId;
+import org.hibernate.search.annotations.Field;
+import org.hibernate.search.annotations.Index;
+import org.hibernate.search.annotations.Indexed;
+import org.hibernate.search.annotations.IndexedEmbedded;
+import org.hibernate.search.annotations.Store;
+
+@Entity
+@Table(name="T_PHONE")
+@Indexed
+public class Phone implements Serializable{
+
+ private static final long serialVersionUID = 1L;
+
+ @Id @GeneratedValue(strategy=GenerationType.AUTO)
+ @Column(name="P_PHONE_ID")
+ @DocumentId
+ private long id;
+
+ @Column(name="P_NUMBER")
+ @Field(index=Index.TOKENIZED, store=Store.YES)
+ private String number;
+
+ @Column(name="P_TYPE")
+ @Field(index=Index.TOKENIZED, store=Store.YES)
+ private String type;
+
+ @Column(name="P_CREATEDON")
+ @Type(type="java.util.Date")
+ private Date createdOn;
+
+ @Column(name="P_LASTUPDATEDON")
+ @Type(type="java.util.Date")
+ private Date lastUpdatedOn;
+
+ @ManyToOne
+ @JoinColumn(name="C_CONTACT_ID")
+ @IndexedEmbedded
+ private Contact contact;
+
+
+ public Phone() {
+ }
+
+ public long getId() {
+ return id;
+ }
+ public void setId(long id) {
+ this.id = id;
+ }
+ public String getNumber() {
+ return number;
+ }
+
+ public void setNumber(String number) {
+ this.number = number;
+ }
+
+ public String getType() {
+ if (null == this.type || "".equals(this.type)) {
+ return "N/A";
+ }
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+ public Date getCreatedOn() {
+ return createdOn;
+ }
+ public void setCreatedOn(Date createdOn) {
+ this.createdOn = createdOn;
+ }
+ public Date getLastUpdatedOn() {
+ return lastUpdatedOn;
+ }
+ public void setLastUpdatedOn(Date lastUpdatedOn) {
+ this.lastUpdatedOn = lastUpdatedOn;
+ }
+
+
+ public Contact getContact() {
+ return contact;
+ }
+
+ public void setContact(Contact contact) {
+ this.contact = contact;
+ }
+
+
+// public int hashCode() {
+// return new HashCodeBuilder().append(new Object[]{this.number,
this.type}).hashCode();
+// }
+//
+// public boolean equals(Object object) {
+// if (!(object instanceof Phone)) {
+// return false;
+// }
+//
+// return new EqualsBuilder().append(new Object[]{}, new Object[]{}).isEquals();
+// }
+//
+// public String toString() {
+// StringBuffer buf = new StringBuffer();
+// displayPhoneDetails(buf, this);
+// return buf.toString();
+// }
+
+ private void displayPhoneDetails(StringBuffer buf, Phone phone) {
+// buf.append(Constants.TAB + Constants.TAB + "Type: " + phone.getType() );
+// buf.append(Constants.SPACE + "Number: " + phone.getNumber() +
Constants.NEW_LINE);
+ }
+}