-->
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.  [ 5 posts ] 
Author Message
 Post subject: Help to create index for legacy database mappings
PostPosted: Wed Oct 29, 2008 7:28 am 
Newbie

Joined: Wed Oct 29, 2008 5:56 am
Posts: 14
I have some problems in creating index and searching, I would like to create index in such a way to include data from all classes and also able to sort on all fields especially on catType.name(actually name is from Label)
except on cat.description. I tried to create a single index out of these classes but I end up with two indexes. One for Cat and other for Label. And I guess I cannot write join like queries on two indexes.
So please tell me a way to create index in such away that I can do what I want. My result should include catId, description, catTypeId,catType Name,catPrority Id,catPriority name.

(I tried with creating a database view with a annotated class for that, but i need automatic update as we dont insert,update that class objects while updating)

My domain model looks like this:


class Cat{

@DocumentID
private Long catId;

@Field(index=Index.TOKENIZED)
private String desciption;

@IndexedEmbedded
private CatType catType;

@IndexedEmbedded
private CatPrority catPrior;

}

class CatType {
@DocumentID
private Long catTypeId;
}

class CatPriority{
@DocumentID
private Long catProrityId;

}

class Label{
@DocumentID
private Long labelId;

@Field(name="name_sort",index=Index.UN_TOKENIZED)
@Field(name="name_token",index=Index.TOKENIZED)
private String name;

@IndexedEmbedded
private Language lang;

@IndexedEmbedded
private CatPriority catPriority;

@IndexedEmbedded
private CatType catType;

}



Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 31, 2008 12:16 pm 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

Assuming that you have an @Indexed on on Cat and you don't want index CatPriority and CatType at all - replace @DocumentId with @Field in the latter two classes (and of course no @Indexed). This should do the trick.

Not sure what the relation is between Cat and Label (if there is any).

And I assume that the two @Field annotations in Label are wrapped inside a @Fields.

Hope this helps,
--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2008 7:42 am 
Newbie

Joined: Wed Oct 29, 2008 5:56 am
Posts: 14
sorry about this empty message , dont know how to delete this


Last edited by indra_in on Tue Nov 25, 2008 7:52 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2008 7:43 am 
Newbie

Joined: Wed Oct 29, 2008 5:56 am
Posts: 14
Thanks for the reply,
hardy.ferentschik wrote:
Assuming that you have an @Indexed on on Cat and you don't want index CatPriority and CatType at all -
--Hardy


I want the id of catType in Cat Index.

hardy.ferentschik wrote:

Not sure what the relation is between Cat and Label (if there is any).

Hope this helps,
--Hardy


No relation between Cat And Label

names of all other entities like CatType, CatPriority are decoupled from their tables and placed in Label so that language specific names can be added with out touching the main tables. this is the schema.

CREATE TABLE `t_cat` (
`cat_id` bigint(20) NOT NULL auto_increment,
`description` varchar(255) collate utf8_unicode_ci default NULL,
`cat_type_id` bigint(20) NOT NULL,
`cat_priority_id` bigint(20) NOT NULL,
`create_date` datetime NOT NULL,
PRIMARY KEY (`cat_id`),
KEY `i_cat_type_id` (`cat_type_id`),
KEY `i_cat_priority_id` (`cat_priority_id`)) ENGINE=InnoDB ..


CREATE TABLE `t_cat_type` (
`cat_type_id` bigint(20) NOT NULL auto_increment,
`create_date` datetime NOT NULL,
PRIMARY KEY (`cat_type_id`)) ENGINE=InnoDB

CREATE TABLE `t_cat_priority` (
`cat_priority_id` bigint(20) NOT NULL auto_increment,
`create_date` datetime NOT NULL,
PRIMARY KEY (`cat_priority_id`)) ENGINE=InnoDB

CREATE TABLE `t_label` (
`label_id` bigint(20) NOT NULL auto_increment,
`name` varchar(255) collate utf8_unicode_ci default NULL,
`code` varchar(255) collate utf8_unicode_ci default NULL,
`language_id` bigint(20) NOT NULL,
`cat_type_id` bigint(20) NOT NULL,
`cat_priority_id` bigint(20) NOT NULL,
`create_date` datetime NOT NULL,
PRIMARY KEY (`label_id`),
KEY `i_cat_type_id` (`cat_type_id`),
KEY `i_cat_priority_id` (`cat_priority_id`)) ENGINE=InnoDB ....

So, this t_label table is like a matrix. The row indicating name for a cat type will have its cat_type_id , name ,language id set to the corresponding values, and cat_priority_id is set to null or zero. similarly, The row representing cat priority name , we set the cat_priority_id and cat_type_id is null.

So my problem is my result set needs the names of properties like catType,CatPriority of Cat.

I have tow approaches at my hand ,
I. having two indexs
1. Cat index 2. Label Index

I execute search query on Cat Index, based on cat id, cat description , cat type Id, cat Prority Id and projecting on same fields. For each result I am executing two queries on Label index to get cat type name and cat priority name. The problem is i am not able to sort the search result based on names of cat type and priority.

II . Having single index using my modified CatType ,CatPriority and Label domains. ( I have indexedEmbedded lableSet for Cat type and priority)

@Indexed
class CatType{
Long catTypeId;

@IndexedEmbedded
@OnetoMany( mappedBy="catTypeId")
Set<Label> labelSet;
}

@Indexed
class Label{
@DocumentID
private Long labelId;

@Fields( {
@Field(name="name_sort",index=Index.UN_TOKENIZED),
@Field(name="name_token",index=Index.TOKENIZED)})
private String name;

@Field(index=Index.UN_TOKENIZED))
private Long langId;

@Field(index=Index.UN_TOKENIZED)
private Long catPriorityId;

@Field(index=Index.UN_TOKENIZED))
private Long catTypeId;

}


But when I use projection like 'cat.catType.labelSet.name' i am getting null for it , though indexed values present for it.

So , I am looking for any optimal approach in this situation. I am actually trying to get entire thing from index.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2008 12:20 pm 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Quote:
I want the id of catType in Cat Index.

As said, if you don't index CatType itself there is no need for @DocumentId. Use @Field instead and the property will still show up in the Cat index. That's how indexing of embedded entities work.

Quote:
II . Having single index using my modified CatType ,CatPriority and Label domains. ( I have indexedEmbedded lableSet for Cat type and priority)
[b]
@Indexed
class CatType{
Long catTypeId;

@IndexedEmbedded
@OnetoMany( mappedBy="catTypeId")
Set<Label> labelSet;
}

@Indexed
class Label{
@DocumentID
private Long labelId;

@Fields( {
@Field(name="name_sort",index=Index.UN_TOKENIZED),
@Field(name="name_token",index=Index.TOKENIZED)})
private String name;

@Field(index=Index.UN_TOKENIZED))
private Long langId;

@Field(index=Index.UN_TOKENIZED)
private Long catPriorityId;

@Field(index=Index.UN_TOKENIZED))
private Long catTypeId;

}


I think that's the way to go. Not sure though whether projection will work then. Projected properties normally have to implement a TwoWayBridge. I don't know out of the top of my head whether you can project an embedded set. Why do you want to project anyway? Is it not much better to work with managed entities instead of object arrays?

--Hardy


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.