feliperazeek/playframework-elasticsearch — Issue #38: Exceptions are thrown when using reverse associations
Author: omaroman
Created: 2011-12-01 19:21:23+00:00
State: open

I have the following escenario:

Author <- Quote (quote has a reference to author)

@MappedSuperclass
public class AuthorAbs extends Model {

// REVERSE ASSOCIATION

@OneToMany(mappedBy = "author", cascade = CascadeType.ALL, fetch = FetchType.LAZY) // name of the variable in the other object that references this object
public List

quotes = new ArrayList

(); // has_many :quotes

// FIELDS

@Required
public String first_name;

@Required
public String last_name;
}

@Entity
@Table(name = "authors")
@ElasticSearchable
public class Author extends AuthorAbs {
public int years;
}

@Entity
@Table(name = "quotes")
@ElasticSearchable
public class Quote extends Model {

// Associations

@ManyToOne() // Optional, targetEntity for indicating where's the relationship
@JoinColumn(name = "author_id") // name of the FK field in this table
// --
@Required
public Author author; // belongs_to_one :author

// Fields

@Required
public String quotation;
}

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

When updating an Author that has at least one Quote, throws the exception

12:34:22,451 ERROR ~
java.io.IOException: Type not allowed [class models.Quote]
at org.elasticsearch.common.xcontent.XContentBuilder.value(XContentBuilder.java:698)
at play.modules.elasticsearch.mapping.impl.CollectionFieldMapper.addToDocument(CollectionFieldMapper.java:94)
at play.modules.elasticsearch.mapping.impl.PlayModelMapper.addModel(PlayModelMapper.java:130)
at play.modules.elasticsearch.mapping.impl.PlayModelMapper.addModel(PlayModelMapper.java:26)
at play.modules.elasticsearch.adapter.ElasticSearchAdapter.indexModel(ElasticSearchAdapter.java:147)
at play.modules.elasticsearch.ElasticSearchIndexAction.invoke(ElasticSearchIndexAction.java:53)
at play.modules.elasticsearch.ElasticSearchIndexer.doJob(ElasticSearchIndexer.java:54)
at play.jobs.Job.doJobWithResult(Job.java:50)
at play.jobs.Job.call(Job.java:146)
at play.jobs.Job$1.call(Job.java:66)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:98)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:206)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)

There's a full app in https://github.com/omaroman/recordtracking/tree/master/samples-and-tests/demo