One-To-Many throws exception when use `Buffer` not `java.util.List` in scala

37 views
Skip to first unread message

Freewind

unread,
Mar 16, 2011, 2:54:58 AM3/16/11
to Ebean ORM
This is my user model

@Entity
@Table(name = "users")
class User {

@Id
var id: Long = _

@Column(unique = true)
var email: String = _

@OneToMany
var questions: Buffer[Question] = _

}

When I user `user.questions` to load the questions, it reports such
error:

java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.rangeCheck(Unknown Source)
at java.util.ArrayList.get(Unknown Source)
at
com.avaje.ebeaninternal.server.core.DefaultBeanLoader.loadMany(Defaul
tBeanLoader.java:128)
at
com.avaje.ebeaninternal.server.core.DefaultServer.loadMany(DefaultSer
ver.java:487)
at
com.avaje.ebeaninternal.server.loadcontext.DLoadManyContext.loadMany(
DLoadManyContext.java:142)
at
com.avaje.ebean.common.AbstractBeanCollection.lazyLoadCollection(Abst
ractBeanCollection.java:153)
at com.avaje.ebean.common.BeanList.init(BeanList.java:116)
at com.avaje.ebean.common.BeanList.iterator(BeanList.java:296)
at scala.collection.JavaConversions
$JListWrapper.iterator(JavaConversion
s.scala:599)
at scala.collection.IterableLike
$class.foreach(IterableLike.scala:79)
at scala.collection.JavaConversions
$JListWrapper.foreach(JavaConversions
.scala:596)
at scala.collection.TraversableOnce
$class.addString(TraversableOnce.scal
a:505)

But if I change that line to:

var questions: java.util.List[Question] = _

Everything works fine.

I think this may be a bug.

PS: DefaultBeanLoader.java

for (int i = 0; i < batch.size(); i++) {
BeanCollection<?> bc = batch.get(i);
Object ownerBean = bc.getOwnerBean();
Object id = many.getParentId(ownerBean);
idList.add(id);
}
int extraIds = batchSize - batch.size();
if (extraIds > 0){
Object firstId = idList.get(0); // line 128: this line
throws NPE
for (int i = 0; i < extraIds; i++) {
idList.add(firstId);
}
}

Rob Bygrave

unread,
Mar 16, 2011, 3:00:43 AM3/16/11
to eb...@googlegroups.com, Freewind
Can you produce a test case that reproduces the problem.

Thanks, Rob.

Freewind

unread,
Mar 16, 2011, 8:33:41 AM3/16/11
to Ebean ORM
I've replied this post several hours ago, but strange not see it.

I created a project in github.com

https://github.com/freewind/ebean-scala-issue

Classes:

https://github.com/freewind/ebean-scala-issue/blob/master/src/main/scala/models.scala

Test cases:

https://github.com/freewind/ebean-scala-issue/blob/master/src/test/scala/mytest.scala

You can clone it and use sbt to run the tests. Or just copy them to
your own computer.

Note the test cases uses:

https://github.com/freewind/ebean-scala-issue/blob/master/src/test/resources/ebean-test.properties

as the property file.

Freewind

unread,
Mar 16, 2011, 4:51:46 AM3/16/11
to Ebean ORM
I've made a complete test case in github.com

https://github.com/freewind/ebean-scala-issue

The models is:

https://github.com/freewind/ebean-scala-issue/blob/master/src/main/scala/models.scala

The test case is:

https://github.com/freewind/ebean-scala-issue/blob/master/src/test/scala/mytest.scala

It requires postgresql, and managed by sbt. If you know sbt, you can
just clone it and test it with sbt.

If not, you can just copy the code of classes and tests( only 2 files
with 4 simple classes)


On 3月16日, 下午3时00分, Rob Bygrave <robin.bygr...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages