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.  [ 3 posts ] 
Author Message
 Post subject: Single Table Inheritance WITHOUGHT Discriminator column
PostPosted: Sun Jul 03, 2011 5:23 am 
Newbie

Joined: Tue May 18, 2010 6:16 am
Posts: 5
Good Morning, my Dear comrades,

This is starting to be come annoying - a simple thing, but hours of struggle, am I getting old??

Right, I am trying to map two Classes to a single table using JPA by Hibernate. The idea is to have only a small subset of columns in parent Class, and bigger/full set in the child Class. There is NO TABLE inheritance involved, only class inheritance.
How can this be accomplished??

Doing this will not work:

Code:
@Entity
@Table(name = "the_table")
class Parent implements Serializable {
}

@Entity
@Table(name = "the_table")
class Child extends Parent implements Serializable {
}


Hibernate assumes default inheritance strategy InheritanceType.SINGLE_TABLE, and is looking for discriminator column - DTYPE by default. But wait - there is no table inheritance, having the discriminator column does not make sence.

I have also taken a look at PolymorphismType.EXPLICIT which did not make any difference. The stack trace is:

Code:
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'apprentice0_.DTYPE' in 'where clause'
   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
   at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
   at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
   at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
   at com.mysql.jdbc.Util.getInstance(Util.java:386)
   at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052)
   at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3597)
   at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3529)
   at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1990)
   at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2151)
   at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2625)
   at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2119)
   at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2281)
   at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:76)
   at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
   at org.hibernate.loader.Loader.getResultSet(Loader.java:1808)
   at org.hibernate.loader.Loader.doQuery(Loader.java:697)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
   at org.hibernate.loader.Loader.loadEntity(Loader.java:1881)


Top
 Profile  
 
 Post subject: Re: Single Table Inheritance WITHOUGHT Discriminator column
PostPosted: Sun Jul 03, 2011 5:31 am 
Newbie

Joined: Tue May 18, 2010 6:16 am
Posts: 5
yeah, one more thing:

The @MapperSuperclass and @Embeddable are of no use as these can not be used in conjunction with @Entity - the parent class has to be an @Entity itself as it is being used for persistence elsewhere.


Top
 Profile  
 
 Post subject: Re: Single Table Inheritance WITHOUGHT Discriminator column
PostPosted: Sun Dec 18, 2011 11:58 pm 
Newbie

Joined: Tue Jul 17, 2007 9:05 am
Posts: 9
Hi,
I'm having the same issue. This pattern is called "lightweight class" and I know how to have it working using XML configuration (as opposed to annotations).
This is explained here:
http://community.jboss.org/wiki/LightweightClass

I tried to do something similar using annotations but that's not working so far.


I tried something like this:

Code:
@Entity
@org.hibernate.annotations.Entity(polymorphism=PolymorphismType.EXPLICIT)
@Table(name="MyTable")
public class Child extends Parent {}

@Entity
@Table(name="MyTable")
public class Parent {}


Unfortunately I'm still getting the same error as you.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.