-->
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: Getting the Exception :=> Circular reference. Duplicate use
PostPosted: Wed May 20, 2009 12:57 pm 
Newbie

Joined: Wed May 20, 2009 12:16 pm
Posts: 5
Hi,
I am trying to create a sample application using Hibernate search .
Using two persistent classes 1)person and 2)event and
getting the exception
please check the code and repply where should I change the code?
=>--------------------------------------------------------------------------------------------------------------
org.hibernate.HibernateException: could not init listeners
at org.hibernate.event.EventListeners.initializeListeners(EventListeners.java:205)
at org.hibernate.cfg.Configuration.getInitializedEventListeners(Configuration.java:1338)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1327)
at Util.HibernateUtil.<clinit>(HibernateUtil.java:9)
at test.SearchPersonEvent.main(SearchPersonEvent.java:34)
Caused by: org.hibernate.search.SearchException: Circular reference. Duplicate use of model.Events in root entity model.Events#personset.events.
at org.hibernate.search.engine.DocumentBuilderContainedEntity.checkForIndexedEmbedded(DocumentBuilderContainedEntity.java:355)
at org.hibernate.search.engine.DocumentBuilderContainedEntity.initializeMemberLevelAnnotations(DocumentBuilderContainedEntity.java:208)
at org.hibernate.search.engine.DocumentBuilderContainedEntity.initializeClass(DocumentBuilderContainedEntity.java:146)
at org.hibernate.search.engine.DocumentBuilderContainedEntity.checkForIndexedEmbedded(DocumentBuilderContainedEntity.java:374)
at org.hibernate.search.engine.DocumentBuilderContainedEntity.initializeMemberLevelAnnotations(DocumentBuilderContainedEntity.java:208)
at org.hibernate.search.engine.DocumentBuilderContainedEntity.initializeClass(DocumentBuilderContainedEntity.java:146)
at org.hibernate.search.engine.DocumentBuilderContainedEntity.init(DocumentBuilderContainedEntity.java:106)
at org.hibernate.search.engine.DocumentBuilderContainedEntity.<init>(DocumentBuilderContainedEntity.java:93)
at org.hibernate.search.impl.SearchFactoryImpl.initDocumentBuilders(SearchFactoryImpl.java:420)
at org.hibernate.search.impl.SearchFactoryImpl.<init>(SearchFactoryImpl.java:119)
at org.hibernate.search.event.ContextHolder.getOrBuildSearchFactory(ContextHolder.java:30)
at org.hibernate.search.event.FullTextIndexEventListener.initialize(FullTextIndexEventListener.java:59)
at org.hibernate.event.EventListeners$1.processListener(EventListeners.java:198)
at org.hibernate.event.EventListeners.processListeners(EventListeners.java:181)
at org.hibernate.event.EventListeners.initializeListeners(EventListeners.java:194)
... 4 more
Exception in thread "main" java.lang.NullPointerException
at test.SearchPersonEvent.main(SearchPersonEvent.java:35)


----------------------------------------------------------------------------------------------------------------------
@Entity
@Indexed
public class Person {

@Id
@GeneratedValue
//@DocumentId
private int id;
private String firstname;
private String lastname;

@IndexedEmbedded
@ManyToMany
private Set<Events> events = new HashSet<Events>();

public Person() {}

/* This is method is special for ading the event*/
public void addEvent(Events events){
this.events.add(events);
}

public Set getEvents() {
return events;
}
public void setEvents(Set events) {
this.events = events;
}

@Field(index=Index.TOKENIZED, store=Store.NO)
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Field(index=Index.TOKENIZED, store=Store.NO)
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}

public String toString()
{
StringBuilder sb =new StringBuilder();
sb.append(" FirstName =").append(firstname);
sb.append(" LastName =").append(lastname);
sb.append(" EventName =").append(events);

return sb.toString();
}
}
----------------------------------------------------------------------------------------------------------------------
@Entity
public class Events {
@Id
@GeneratedValue
private int id;

@Field(index=Index.TOKENIZED, store=Store.NO)
private String title;
private Date date;

@IndexedEmbedded
@ManyToMany
private Set<Person> personset = new HashSet<Person>();

public Events()
{}

public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}

public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}

public String toString()
{
StringBuilder sb =new StringBuilder();
sb.append("EventName =").append(title);

return sb.toString();
}

/* Setter,getter and add method for personset*/
public void addPerson(Person person)
{
this.personset.add(person);
}
public Set<Person> getPersonset() {
return personset;
}

public void setPersonset(Set<Person> personset) {
this.personset = personset;
}

}

----------------------------------------------------------------------------------------------------------------------

<class name="model.Person" table="Person">
<id name="id" column="person_id">
<generator class="native"/>
</id>
<property name="firstname" column="first_name" type="java.lang.String"/>
<property name="lastname" column="last_name" type="java.lang.String"/>

<set name="events" table="PERSON_EVENT" cascade="save-update,persist">
<key column="person_id" />
<many-to-many column="event_id" class="model.Events" />
</set>

</class>
----------------------------------------------------------------------------------------------------------------------
<class name="model.Events" table="Events">
<id name="id" column="event_id" >
<generator class="native" />
</id>
<property name="title" type="java.lang.String" />
<property name="date" column="event_date" type="java.util.Date" />

<set name="personset" table="PERSON_EVENT" inverse="true">
<key column="event_id"/>
<many-to-many column="person_id" class="model.Person" />
</set>
</class>


Top
 Profile  
 
 Post subject: Re: Getting the Exception :=> Circular reference. Duplicate use
PostPosted: Wed May 20, 2009 5:30 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi,
there are @IndexedEmbedded on both sides of the relation;
The Events.personset should be annotated with @IndexedEmbedded, if this is a bi-directional relation.

I'm not sure about what you are trying to map, IMHO there's a missing "mappedBy" on one side of the relation.

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


Top
 Profile  
 
 Post subject: Re: Getting the Exception :=> Circular reference. Duplicate use
PostPosted: Thu May 21, 2009 9:24 am 
Newbie

Joined: Wed May 20, 2009 12:16 pm
Posts: 5
Hi Sanne,
Thanks for quick repply.
Now code is running fine.

Regards,
Vijay


Top
 Profile  
 
 Post subject: Exception--Entity to index is not an @Indexed entity: com.pa
PostPosted: Thu May 21, 2009 10:04 am 
Newbie

Joined: Wed May 20, 2009 12:16 pm
Posts: 5
Hi,
I am getting exception =>

Exception in thread "main" java.lang.IllegalArgumentException: Entity to index is not an @Indexed entity: ava.lang.Object;
at org.hibernate.search.impl.FullTextSessionImpl.index(FullTextSessionImpl.java:149)
at com.pack.company.CompSearch.main(CompSearch.java:51)

So how to avoid this ?
Please ,Suggest all the changes in code.

The code is as follow:


@Entity
@Indexed
public class Employee {

@Id
@GeneratedValue
@DocumentId
private Integer empId;

@Field(index=Index.TOKENIZED, store=Store.NO)
private String empName;
@Field(index=Index.TOKENIZED, store=Store.NO)
private String empDesignation;
@Field(index=Index.TOKENIZED, store=Store.NO)
private Integer empManager;

@Field(index=Index.TOKENIZED, store=Store.NO)
private Double empSalary;

/** nullable persistent field */
private Date empDOJ;

@ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.MERGE} )
@JoinColumn(name="PROJ_ID")
@IndexedEmbedded
private Project project;

/* Getters ans setters*/

}
-----------------------------------------------------------
/*project class*/

@Entity
@Indexed
public class Project {

@Id
@GeneratedValue
private Integer projectId;
@Field(index=Index.TOKENIZED, store=Store.NO)
private String projectName;
@Field(index=Index.TOKENIZED, store=Store.NO)
private String projectDesciption;

@OneToMany(mappedBy="project")
@ContainedIn
/* @ContainedIn is only useful on associations pointing to entities as opposed to embedded (collection of) objects*/
private Set<Employee> employees;
/* Getters ans setters*/

}
=====================================================================
/* And mapping files as*/
<hibernate-mapping>
<class name="com.pack.model.Employee" table="EMPLOYEE">
<id name="empId"
type="java.lang.Integer"
column="EMP_ID">
<generator class="native"/>
</id>
<!-- other proprties-->

<many-to-one name="project"
class="com.pack.model.Project"
not-null="true"
cascade="all">
<column name="PROJ_ID"/>
</many-to-one>
</class>
</hibernate-mapping>
------------------------------------------------------------------------
<hibernate-mapping>
<class name="com.pack.model.Project" table="PROJECT">
<id
name="projectId"
type="java.lang.Integer"
column="PROJ_ID">
<generator class="native"/>
</id>
<!-- other proprties-->

</many-to-one>
<set
name="employees"
inverse="true"
table="EMPL"
lazy="true"
cascade="all"
fetch="join">
<key column="PROJ_ID" not-null='true'/>
<one-to-many class="com.pack.model.Project"/>
</set>
</class>
</hibernate-mapping>
=====================================================================

/*main logic */

SessionFactory factory = Util.HibernateUtil.getSessionFactory();
Session session = factory.openSession();
FullTextSession fullTextSession = Search.getFullTextSession(session);
Transaction tx = fullTextSession.beginTransaction();

List obj = session.createSQLQuery
("select e.EMP_ID,e.EMP_NAME,d.PROJ_NAME from employee e,Project d where e.PROJ_ID =d.PROJ_ID").list();
for (Object e :obj ) {

fullTextSession.index(o);//throws exception here
}
}


Top
 Profile  
 
 Post subject: Re: Getting the Exception :=> Circular reference. Duplicate use
PostPosted: Thu May 21, 2009 12:04 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Quote:
List obj = session.createSQLQuery

you are doing an SQL query, this is not returning Hibernate managed objects.
you'll have to do something like
Code:
List list = session.createQuery( "from Employee" ).list();


You should learn about Hibernate queries first, much better than SQL selects.

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


Top
 Profile  
 
 Post subject: Re: Getting the Exception :=> Circular reference. Duplicate use
PostPosted: Fri May 22, 2009 1:50 am 
Newbie

Joined: Wed May 20, 2009 12:16 pm
Posts: 5
Hi Sanne,

I am getting the same Exception when I tried the HQL query . The query is as follow

List obj = session.createQuery("select emp.empName,emp.empDesignation,prj.projectName from Employee emp,Project prj where emp.project = prj.projectId").list();

for (Object e :obj ) {
fullTextSession.index(e);
}

But when I use the single Entity then it works fine . All the field of Employee table are searchable.
for the following code :-


List obj = session.createQuery("from Employee as obj ").list();
for (Object e :obj ) {
Employee p = (Employee ) e;
fullTextSession.index(e);
}


Top
 Profile  
 
 Post subject: Re: Getting the Exception :=> Circular reference. Duplicate use
PostPosted: Fri May 22, 2009 3:27 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Quote:
List obj = session.createQuery("select emp.empName,emp.empDesignation,prj.projectName from Employee emp,Project prj where emp.project = prj.projectId").list();

this is going to return an list of arrays (the empName,empDesignation,projectName values) but not an entity, so...
Code:
for ( Object e : obj ) {
   fullTextSession.index( e );
}


will fail as fullTextSession.index expects an @indexed entity, not an array of objects.
Querying only for Employees should be much simpler. I don't understand why you are joining the Employee with the project and selecting fields.
What is your goal?

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


Top
 Profile  
 
 Post subject: Saying Thanks
PostPosted: Mon May 25, 2009 2:42 am 
Newbie

Joined: Wed May 20, 2009 12:16 pm
Posts: 5
Hi Sanne ,

Thanks for repply.
My problem has solved.
Actualy was I doing sample program to search data from three associted tables
and now started to add differant Hibernate Search functionalities to it .

Regards,
Vijay


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.