-->
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.  [ 2 posts ] 
Author Message
 Post subject: Need Help - issue in using composte keys in search
PostPosted: Sat Apr 10, 2010 2:46 pm 
Newbie

Joined: Sat Apr 10, 2010 2:06 pm
Posts: 1
I am new to Hibernate search and I am trying to use in my current project. I have three persistent classes which are mapped with each other and two of them are using the composit keys. The relationship as following:

a) An article can have multiple version. Article has an unique id, article ID (integer) and a collection of version object
b) many versions are mapped to a single article. The primary key is a composte key of a version id and article id. Version has an Embeddable key which has version id (integer) and article as memeber.
c) a version can have multiple contents in different language. So again contnet has a composite key of article version and language object.
d) content has a title field and a body field, which should allow full text search.

So wen i do a full text search, I should get a list of contents but, I do not find a suitable eaxample of implementing a twowayfieldbridge where the PK class has an object inside it.
Can someone kindly help me to understand what are my options here.

Any help will be highly appreciated.

I am pasting those three persistent classes below :




Article Class:
@Entity
@Table(name = "article")
public class Article {

private Integer id;
private Timestamp updatedON;
private Timestamp startsON;
private Timestamp expiresON;
private Timestamp publishedDate;
private Collection<Version> versions;

/**
* @return the id
*/
@Id
@Column(name = "id")
@GeneratedValue(strategy=GenerationType.IDENTITY)
@BusinessKey
public Integer getId() {
return id;
}

/**
* @param id the id to set
*/
public void setId(Integer id) {
this.id = id;
}

@OneToMany(mappedBy="id.article", fetch=FetchType.EAGER,cascade=CascadeType.ALL)
public Collection<version> getVersions() {
return versions;
}

public void setVersions(Collection<version> versions) {
this.versions = versions;
}
}


version Class


@Entity
@Table(name = "version")
public class Version {

private VersionPK id;
private Collection<Content> contents;
private String createdBy;
private String expiredBy;

/**
* @return the id
*/
@Id
public VersionPK getId() {
return id;
}

/**
* @param id the id to set
*/
public void setId(VersionPK id) {
this.id = id;
}

/**
* @return the articleVersionInfoPK
*/


@Embeddable
public static final class VersionPK {

/**
* Serial version.
*/
private static final long serialVersionUID = 1L;

private Integer versionID;
private Article article;

public VersionPK () {

}

@Column(name = "versionID")
@BusinessKey
public Integer getVersionID() {
return versionID;
}

public void setVersionID(Integer versionID) {
this.versionID = versionID;
}

/**
* @return the article
*/
@ManyToOne(cascade=CascadeType.ALL,fetch=FetchType.LAZY)
@JoinColumn(name = "articleID", referencedColumnName = "articleID")
public Article getArticle() {
return article;
}

/**
* @param articleMetaData
* the articleMetaData to set
*/
public void setArticle(Article article) {
this.article= article;
}

}


/**
* @return the contents
*/
@OneToMany(mappedBy = "id.version")
public Collection<Content> getContents() {
return contents;
}

/**
* @param contents
* the contents to set
*/

public void setContents(Collection<Content> contents) {
this.contents = contents;
}

}

Content class:

@Entity
@Table(name = "content")
public class Content {


private ContentPK id;
private String articleTitle;
private String articleLongTitle;
private String contentBody;

/**
* @return the id
*/
@Id
public ContentPK getId() {
return id;
}


/**
* @param id the id to set
*/
public void setId(ContentPK id) {
this.id = id;
}


/**
* @return the articleTitle
*/
@Column(name="title")
public String getArticleTitle() {
return articleTitle;
}


/**
* @param articleTitle the articleTitle to set
*/
public void setArticleTitle(String articleTitle) {
this.articleTitle = articleTitle;
}


/**
* @return the articleLongTitle
*/
@Column(name="articleTitleLong")
public String getArticleLongTitle() {
return articleLongTitle;
}


/**
* @param articleLongTitle the articleLongTitle to set
*/
public void setArticleLongTitle(String articleLongTitle) {
this.articleLongTitle = articleLongTitle;
}


@Embeddable
public static final class ArticleContentPK extends BaseObject {

/**
* Serial version.
*/
private static final long serialVersionUID = 1L;

private Version version;
private Language language;

public ContentPK() {
super();
}

/**
* @return the articleVersion
*/
@ManyToOne(cascade = CascadeType.ALL, fetch=FetchType.LAZY)
@JoinColumns( {
@JoinColumn(name = "articleID", referencedColumnName = "articleID", unique = true),
@JoinColumn(name = "verersionID", referencedColumnName = "verersionID", unique = true) })
@BusinessKey
public version getVersion() {
return version;
}

/**
* @param articleVersion
* the articleVersion to set
*/
public void setVersion(Version version) {
this.version= version;
}

}




/**
* @return the contentBody
*/
@Lob
@Column(name="article_Body")
public String getContentBody() {
return contentBody;
}


/**
* @param contentBody the contentBody to set
*/
public void setContentBody(String contentBody) {
this.contentBody = contentBody;
}


}



Thanking you in advance.


Top
 Profile  
 
 Post subject: Re: Need Help - issue in using composte keys in search
PostPosted: Mon Apr 12, 2010 2:24 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hello,
there's an example in the tests sources, you can download the sources or see it on fisheye:
PersonPKBridge
PersonPK
Person

Remember your primary keys must have an equals implementation, you basically need to create a new instance of the PK type and set the parts of it by parsing the string(s) from the Document in such a way that you'll be able to load the full entity from the primary key.

Note that the example is encoding the id in a single field, and also using two fields to store both firstName and lastName separately.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

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.