-->
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.  [ 2 posts ] 
Author Message
 Post subject: Inhiritance problems
PostPosted: Sun Aug 23, 2009 9:04 pm 
Beginner
Beginner

Joined: Tue Dec 21, 2004 11:53 am
Posts: 42
Hibernate Annotations 3.4.0
Hibernate Entity Manager: 3.4.0
Database: mysql 5.1

Hello there! Here's a piece of a REALLY REALLY simple mapping that should be working ...

Code:
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="BTYPE",discriminatorType=DiscriminatorType.STRING)
public abstract class BillingDetails  {
   
   @Id
   @GeneratedValue(strategy=GenerationType.AUTO)
   private Integer id;



@Entity
@DiscriminatorValue("CC")
public class CreditCard extends BillingDetails {



@Entity
@DiscriminatorValue("BA")
public class BankAccount extends BillingDetails{



But it seems that Hibernate can not figure it out. It throws an Exception:

Code:
javax.persistence.PersistenceException: [PersistenceUnit: caveatPU] Unable to configure EntityManagerFactory
   at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:265)
   at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:125)
   at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
   at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
   at org.acme.training.jpa.util.test.BaseJPATest.testConnection(BaseJPATest.java:26)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethodRunner.java:99)
   at org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRunner.java:81)
   at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
   at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
   at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
   at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:66)
   at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
   at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
   at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
   at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
   at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
   at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: org.hibernate.AnnotationException: Cannot find the expected secondary table: no CREDIT_CARD available for org.acme.training.jpa.auction.model.CreditCard
   at org.hibernate.cfg.Ejb3Column.getJoin(Ejb3Column.java:293)
   at org.hibernate.cfg.Ejb3Column.getTable(Ejb3Column.java:272)
   at org.hibernate.cfg.annotations.SimpleValueBinder.make(SimpleValueBinder.java:222)
   at org.hibernate.cfg.annotations.PropertyBinder.bind(PropertyBinder.java:122)
   at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1667)
   at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:754)
   at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:546)
   at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:291)
   at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1148)
   at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1226)
   at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:173)
   at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:854)
   at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:191)
   at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:253)
   ... 24 more


I'm having issues with ALL types of mappings in Hibernate. I tried switching to 3.2 version, but same problem persist.

In this specific case, If I use org.hibernate.Entity annotation instead of java.persistence it works.

Other annoying bug is, that even with the Hibernate annotation, When using TABLE_PER_CLASS Strategy the hbm2ddl does not create the mapped superclass properties to the concrete tables

Anyone get Inheritance working on this version of Hibernate?


Top
 Profile  
 
 Post subject: Re: Inhiritance problems
PostPosted: Sun Aug 23, 2009 10:59 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Quote:
CREDIT_CARD


Does your credit card have an instance of a credit card mapped? Self-referencing in the config files?

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


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