Inheritance strategy "Table per class"

956 views
Skip to first unread message

Saulius

unread,
Mar 18, 2011, 7:20:58 AM3/18/11
to Ebean ORM
Hi,

I've been searching for alternative ORM for our Hibernate + JPA
solution. I ended up with Ebean as it suits me best.

Anyway, in our current solution we have most entities to extend a
IdBeanEntity which looks like this:

@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class IdBeanEntity implements IdBean, EntityBean {

@Id @GeneratedValue(strategy = GenerationType.SEQUENCE)
protected Long id;

.....
}

So when I need another entity with Long id, I just do:

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

private String username;

private String password;

.....
}

When I try selecting Ebean.find(User.class, 1851519l) I get an
exception:

javax.persistence.PersistenceException: Query threw
SQLException:ERROR: syntax error at or near "t0"
Bind values:[1867776]
Query was:
select t0.dtype as c0, t0.id as c1, t0.username as c2, t0.password as
c3, t0.accumulated_discount as c4, t0.registered as c5, t0.last_login
as c6, t0.locale as c7, t0.balance as c8
from users t0
where t0. and t0.id = ?

at
com.avaje.ebeaninternal.server.query.CQuery.createPersistenceException(CQuery.java:
849)
at
com.avaje.ebeaninternal.server.query.CQuery.createPersistenceException(CQuery.java:
829)
at
com.avaje.ebeaninternal.server.query.CQueryEngine.find(CQueryEngine.java:
290)
at
com.avaje.ebeaninternal.server.query.DefaultOrmQueryEngine.findId(DefaultOrmQueryEngine.java:
154)
at
com.avaje.ebeaninternal.server.core.OrmQueryRequest.findId(OrmQueryRequest.java:
310)
at
com.avaje.ebeaninternal.server.core.DefaultServer.findId(DefaultServer.java:
1187)
at
com.avaje.ebeaninternal.server.core.DefaultServer.find(DefaultServer.java:
1091)
at
com.avaje.ebeaninternal.server.core.DefaultServer.find(DefaultServer.java:
1078)
at com.avaje.ebean.Ebean.find(Ebean.java:855)


Tried it with and without enhanced approach - same result.

I can assume from the SQL query, that Ebean tries to select
discriminator type or something, but I don't need discriminator having
inheritance strategy "Table per class".

Does Ebean support "Table per class" inheritance strategy?

edge

unread,
Mar 18, 2011, 7:41:53 AM3/18/11
to Ebean ORM
Glad to hear you like Ebean!

I think you need to use @MappedSuperclass on your abstract class - its
not an entity

@MappedSuperclass
public abstract class IdBeanEntity implements IdBean, EntityBean {

and then on your concrete entity
@Entity
@Table(name = "users")
public class User extends IdBeanEntity {

BTW: You should also add a version property to your base class if you
want to use optimistic locking
e.g.
@Version
private int version;

Rob Bygrave

unread,
Mar 20, 2011, 3:01:46 AM3/20/11
to eb...@googlegroups.com
Also note Ebean does not support:  InheritanceType.TABLE_PER_CLASS

Saulius Pačekajus

unread,
Mar 21, 2011, 9:10:32 AM3/21/11
to eb...@googlegroups.com
Thank you guys for your answers!

@MappedSuperclass is actually what I need (it seems I need to study JPA a bit more) - it suits better than InheritanceType.TABLE_PER_CLASS. And those 3 cases I've been actually using InheritanceType.TABLE_PER_CLASS - well it can easily be changed to work with @MappedSuperclass.

Now I'm reviewing the whole ~100 entity data model to make it work on Ebean. Nothing too complex so far I'd say!
Reply all
Reply to author
Forward
0 new messages