I'm trying to use Hibernate Annotation for Hibernate Search and I'm stuck. I'm trying to link the relationship between these 3 tables: Business, Business_Address, and Address.
Here's my table hbm.xml:
Code:
<hibernate-mapping>
<class name="com.RXCoreApp.datamodel.BusinessCbo" table="Busines" schema="dbo" catalog="RX">
<id name="businessId" type="java.lang.Integer">
<column name="Business_Id" />
<generator class="identity"></generator>
</id>
<property name="businessName" type="java.lang.String">
<column name="Business_Name" />
</property>
<set name="businessAddresses" inverse="true" cascade="all-delete-orphan">
<key>
<column name="Business_Id" />
</key>
<one-to-many class="com.RXCoreApp.datamodel.BusinessAddressCbo" />
</set>
</class>
</hibernate-mapping>
Code:
<hibernate-mapping>
<class name="com.RXCoreApp.datamodel.BusinessAddressCbo" table="Business_Address" schema="dbo" catalog="RX">
<id name="businessAddressId" type="java.lang.Integer">
<column name="Business_Address_Id" />
<generator class="identity" />
</id>
<many-to-one name="address" class="com.RXCoreApp.datamodel.AddressCbo" fetch="select">
<column name="Address_Id" />
</many-to-one>
<many-to-one name="busines" class="com.RXCoreApp.datamodel.BusinessCbo" fetch="select">
<column name="Business_Id" />
</many-to-one>
<many-to-one name="addressType" class="com.RXCoreApp.datamodel.AddressTypeCbo" fetch="select">
<column name="Address_Type_Id" />
</many-to-one>
</class>
</hibernate-mapping>
Code:
<hibernate-mapping>
<class name="com.RXCoreApp.datamodel.AddressCbo" table="Address" schema="dbo" catalog="RX">
<id name="addressId" type="java.lang.Integer">
<column name="Address_Id" />
<generator class="identity"></generator>
</id>
...
<set name="businessAddresses" inverse="true" cascade="all-delete-orphan">
<key>
<column name="Address_Id" />
</key>
<one-to-many class="com.RXCoreApp.datamodel.BusinessAddressCbo" />
</set>
</class>
</hibernate-mapping>
Here's my Annotation class:
Code:
@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@Table(name = "Busines")
@Indexed(index="indexes/businesses")
public abstract class AbstractBusinessCbo implements java.io.Serializable {
// Fields
@Id
@DocumentId
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "BUSINESS_ID", nullable = false)
private Integer businessId;
@OneToMany
@JoinColumn (name = "BUSINESS_ID")
private Set businessAddresses = new HashSet(0);
...
Code:
public abstract class AbstractBusinessAddress implements java.io.Serializable {
// Fields
private Integer businessAddressId;
private AddressCbo address;
private BusinessCbo busines;
...
Code:
@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@Table(name = "Address")
@Indexed(index="indexes/addresses")
public abstract class AbstractAddressCbo implements java.io.Serializable {
@Id
@DocumentId
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ADDRESS_ID", nullable = false)
private Integer addressId;
private Set businessAddresses = new HashSet(0);
...
Here's my FULLTEXT search:
Code:
FullTextSession fullTextSession = Search.createFullTextSession( session );
MultiFieldQueryParser parser = new MultiFieldQueryParser(new String[]{
"businessName", "businessAddresses.address.cityName", "businessAddresses.address.state"}, new StandardAnalyzer());
org.apache.lucene.search.Query query = parser.parse(searchString);
searchQry = fullTextSession.createFullTextQuery(query, BusinessCbo.class);
countQry = searchQry;
result = paginator.getPaginatdResult(session,countQry,searchQry,paginationControl_);
Can someone show me how to declare the join relationship using Annotation?