ClassCastException cannot be cast to com.avaje.ebean.bean.EntityBean in 9.5.1 (works in 9.3.1)

492 views
Skip to first unread message

Glen Peterson

unread,
Jun 16, 2017, 11:33:51 AM6/16/17
to Ebean ORM
When I call in Java (this worked with 9.3.1):

TaintedS bookSlug = rP.urlTokens().get(1);
EbeanServer ebeanServer = Ebean.getServer(null);
Book book = ebeanServer.find(Book.class)
.where().eq("slug", bookSlug)
.findUnique();

With 9.5.1 I get:
java.lang.ClassCastException: planbase.autoComWebUtils.TaintedS cannot be cast to com.avaje.ebean.bean.EntityBean

This is the line in ebean with the ClassCastException:

Here's Book (in Kotlin)

class Book(@Column var title:TaintedS,
@Column var titleLong:TaintedS,
@Column var subTitle: TaintedS? = null,
@Column var slug: TaintedS) : Deletable() {

Here's I think the relevant excerpts of TaintedS (in Java).  It has all the same method signatures as java.lang.String (which I don't show here) except that it's not a String, so the type system more-or-less forces me to encode it before writing to output.  I know this is weird, but I haven't significantly changed this class since I was using it with Hibernate in 2013 and it's worked with ebean up through 9.3.1:

public class TaintedS implements Comparable<TaintedS>, Serializable {

private static final long serialVersionUID = 20130917223500L;

private final String s;

/**
EBean seems to want this to be public even though Josh Bloch isn't
     into public constructors.

@param str the string to wrap
*/
public TaintedS(String str) { s = str; }

/**
Using this trusts user input, defeating the purpose of this class.
     This is deprecated so you don't do so accidentally.
     It uses warning signs as delimiters in case you do anyway!
*/
@Deprecated
public String toString() {
// ⛔ No Entry (road sign) - always bold and easy to see everywhere. Often red. 2017-01-27.
return "⛔" + s + "⛔";
}

@Override
public int hashCode() {
// It is critically important (for comparing to Strings) that this be 100% compatable with
// string.hashcode(). Don't get cute adding random stuff to make it different.
return s.hashCode();
}

@Override
public boolean equals(Object other) {
if (this == other) { return true; }
if ( !(other instanceof TaintedS) ) { return false; }
final TaintedS that = (TaintedS) other;
return this.s.equals(that.s);
}
}

I hope that makes some kind of sense.  Let me know if I can provide any more information, or if this is the wrong place to post, or if I'm doing something similarly stupid.


Probably related issue:
I get a null pointer exception here:
When I call:

List<Book> books = ebeanServer.find(Book.class)
.orderBy().asc("title")
.findList();

Again, works with 9.3.1, breaks in 9.5.1.

Oh...  I'm doing maven enhancement here:

<plugin>
<groupId>org.avaje.ebean</groupId>
<artifactId>ebean-maven-plugin</artifactId>
<version>8.2.1</version>
<executions>
<execution>
<id>main</id>
<phase>process-classes</phase>
<configuration>
<transformArgs>debug=1</transformArgs>
</configuration>
<goals>
<goal>enhance</goal>
</goals>
</execution>
</executions>
</plugin>

When I actually run and see the error, I use IntelliJ IDEA Ebean 8.x Enhancement plugin version 8.2.2

For completeness, when I build, I get this (I think unrelated) error with either version of ebean:
Error:Exception trying to enhance:com.goalqpc.memJogLib.autoCompile.ChapterUpload error:Error getting common superClass for org/organicdesign/fp/collections/PersistentHashMap and org/organicdesign/fp/collections/ImMap - org/organicdesign/fp/collections/UnmodMap$AbstractUnmodMap (wrong name: org/organicdesign/fp/collections/UnmodMap)

openjdk version "1.8.0_131"
OpenJDK Runtime Environment (build 1.8.0_131-8u131-b11-0ubuntu1.16.04.2-b11)
OpenJDK 64-Bit Server VM (build 25.131-b11, mixed mode)

Kotlin 1.1.2-5
IntelliJ 2017.1.4
Ubuntu 16.04 64-bit

Glen Peterson

unread,
Jun 16, 2017, 2:25:47 PM6/16/17
to Ebean ORM
Hmm... I think I have an even bigger issue with 9.5.1.  db-create-all.sql is now missing all the fields of type TaintedString in my Kotlin classes.  For instance, Chapter no longer has name or file_name, but still has free, id, and deleted (id and deleted are inherited from Deletable()).

@Entity
@Table(uniqueConstraints = arrayOf(UniqueConstraint(columnNames = arrayOf("fileName"))))
class Chapter(@Column var name: TaintedS,
@Column var fileName:TaintedS?) : Deletable() {

@Column var free:Boolean = false

So I think the problem is that my TaintedS class no longer works as a wrapper for String.  How do I make ebean recognize it?

Glen Peterson

unread,
Jun 16, 2017, 3:54:19 PM6/16/17
to Ebean ORM
I think this is called "custom type conversation."  This is how Hibernate does it:
and

Well, Hibernate used to do that.  I haven't used it in a while.

Did ebean used to "enhance" the bytecode to TaintedS so that it could get/set the single String field?  Did it serialize/deserialize to a varchar?  Did it call toString() then pass the varchar to the single-argument constructor?  Whatever it used to do, it looks like it's not doing that any more.

Glen Peterson

unread,
Jun 16, 2017, 4:59:37 PM6/16/17
to Ebean ORM
Just upgraded ebean to 10.3.1, maven-plugin to 10.2.1, and IDEA plug-in to 10.x.  Same issue.

Roland Praml

unread,
Jun 18, 2017, 4:20:10 AM6/18/17
to Ebean ORM
With release 10 com.avaje.ebean was renamed to io.ebean.

So check your code and all dependencies if there are refenrences to com.avaje.ebean

cheers
Roland

Glen Peterson

unread,
Jun 19, 2017, 9:00:41 AM6/19/17
to Ebean ORM
Thank you.  I did that before sending my email that I had upgraded.  I also narrowed down that it works with 9.3.1 and breaks with 9.4.1.  You're probably all wondering why I haven't upgraded before now?  I used Hibernate for years and found a huge number of headaches every time I upgraded, so I'm a little upgrade shy.  That said, I'm in the habit of upgrading all tools every few months and when I tried to upgrade ebean, it broke and I gave up too quickly.  There's also always the hope that someone else will find and trouble-shoot the issue so I don't have to.

I guess today I'll spend an hour undoing some of the changes from 9.3.1 to 9.4.1 on my machine to find exactly which one broke this feature.  Several files were deleted that looked like possible candidates, so it may be as simple as undeleting one?

Glen Peterson

unread,
Jun 19, 2017, 11:29:25 AM6/19/17
to Ebean ORM
I think the root issue is that ebean stopped recognizing my TaintedS String-wrapper class between 9.3.1 and 9.4.1.  I use it for most varchar fields.  All varchar fields wrapped in TaintedS are missing from db-create-all.sql.  Two non-String varchar fields survived.  They are both enum types that wrap a text field.  It's annotated @EnumValue on each value of the enum.

I wonder if it's "Remove support for Immutable Compound Values #908" that did it?

Rob Bygrave

unread,
Jun 21, 2017, 5:56:01 AM6/21/17
to ebean@googlegroups
Hi Glen,

Sorry, I have been pretty busy of late so behind on some of these posts etc.


> TaintedS ... "Remove support for Immutable Compound Values #908" that did it?

Yes, this will be the issue.  Ebean 'had' some automatic detection and support for Domain Driven Design immutable types and immutable compound types.  So TaintedS would have been detected as an immutable type that held one or more supported types (in this case String).

So #908 was about the process of keeping internals as simple as possible etc.

Have you been able to move successfully from TraintedS to String ?



Cheers, Rob.


--

---
You received this message because you are subscribed to the Google Groups "Ebean ORM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ebean+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages