-->
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.  [ 8 posts ] 
Author Message
 Post subject: another problem updating index files
PostPosted: Fri Dec 04, 2009 7:31 am 
Newbie

Joined: Wed Mar 08, 2006 11:12 am
Posts: 16
Hello,
I'm facing problem with update of index files, when dependent entity is being updated or inserted.
I have following entities:

Code:
@Indexed
class Ticket {

@Id
private long id;

@OneToMany(mappedBy="ticket", cascade=CascadeType.ALL)
@IndexedEmbedded
private List<Note> notes = new ArrayList<Note>();
}

class Note {

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

@ManyToOne(fetch=FetchType.LAZY, optional = false)
@ContainedIn
private Ticket ticket;
}


And i want the index files of Ticket entity being updated, when user updates/creates new dependent Note entity. Previous code works, but with one important problem. The index files of Ticket entity are updated, but new Note is not indexed to already existing and indexed Ticket, but new Ticket entity is indexed and stored with ticketId = 0 in index files. I'm using Luke to check index files.
I have no idea what might be wrong. Thanx for any hint.


Top
 Profile  
 
 Post subject: Re: another problem updating index files
PostPosted: Fri Dec 04, 2009 2:22 pm 
Hibernate Team
Hibernate Team

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

how do you create the new Note instance and how to you attach it to the ticket? Somehow you also have to set the association from the Ticket side I guess. Sounds a liitle like wrong Hibernate usage from your part, but to be sure you would have to post your annotated classes together with your session code (what happens between opening and closing a session).

--Hardy


Top
 Profile  
 
 Post subject: Re: another problem updating index files
PostPosted: Fri Dec 11, 2009 7:38 am 
Newbie

Joined: Wed Mar 08, 2006 11:12 am
Posts: 16
Hi,
our application is running in hibernate + jpa environment.
so, what we do is following:

web app:
Ticket ticket = ....// getting already persisted ticket entity
Note note = new Note();
note.setTicket(ticket);
...filling some Note attribute

and now we call ejb bean to merge new data. the code inside ejb is:

@PersistenceContext
private EntityManager em;

merge method:
Session s = ((EntityManagerImpl) em.getDelegate()).getSession();
s.merge(note);
s.flush();

is this detailed enough?
thanx for any hint or remark


Top
 Profile  
 
 Post subject: Re: another problem updating index files
PostPosted: Fri Dec 11, 2009 9:27 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
In your code you are not adding the note to the list of notes in tickets. You have to update both ends of a bi-directional relationship. Could that be your problem?

--Hardy


Top
 Profile  
 
 Post subject: Re: another problem updating index files
PostPosted: Fri Dec 11, 2009 10:08 am 
Newbie

Joined: Wed Mar 08, 2006 11:12 am
Posts: 16
i extended code to update both ends of this relationship. it means

notice.setTicket(ticket);
ticket.getNotices().add(notice);

but the result was exactly the same. after saving notice (not ticket!) the indexed value of ticketId is 0.


Top
 Profile  
 
 Post subject: Re: another problem updating index files
PostPosted: Fri Dec 11, 2009 10:13 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
You will have to save ticket as well. Before you can get index updates in case a note gets "updated", you have to make sure the note actually is part of the ticket.
So for new notes you have to add them to the corresponding ticket and save the ticket.

--Hardy


Top
 Profile  
 
 Post subject: Re: another problem updating index files
PostPosted: Fri Dec 11, 2009 10:32 am 
Newbie

Joined: Wed Mar 08, 2006 11:12 am
Posts: 16
ok, that is more or less our current solution. we save already persisted ticket with new notice, but we thought it is more workaround than solution.

because in this case i do not understand, what the annotation @ContainedIn is good for. i understood, that it says hibernate search module to update index files of 'parent' entity (ticket in our case), when dependent entity (notice in our case) is updated. it works only for db updates not for db inserts?


Top
 Profile  
 
 Post subject: Re: another problem updating index files
PostPosted: Fri Dec 11, 2009 10:36 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Yes, it only works for updates. @ContainedIn cannot work until the contained object is really added to the containing entity. It is your job to make sure that on an insert both sides of a bi-directional association get properly set.

--Hardy


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