-->
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: Single table inhertance failed on hbm2ddl
PostPosted: Wed Jul 02, 2008 5:36 pm 
Newbie

Joined: Wed Jul 02, 2008 4:56 pm
Posts: 3
We are reporting an issue during the database schema generating process using hbm2ddl tools against some entities using single-table inheritance strategy. It works fine for the simple hierarchy entity mappings. It breaks down when we try to modeling the data using single-table inheritance in relational entities. Here is one example:

The main object:
Code:
@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorValue("S")
public class MySub1 extends AbstractMySuper {
   
    @ManyToOne(fetch = FetchType.EAGER)
    private MySub1 underlying;
   
    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy="mysub1")
    private List<ExcludedMySub1> excludedSub1;
   
    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy="mysub1")
    private List<IncludedMySub1> includedSub1;
   
    ...
}


The relationship super-class:

Code:
@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="myType",discriminatorType=DiscriminatorType.STRING, length=1)
public abstract class AbstractMySub1 {
   
    @Id
    @SequenceGenerator(name = "AbstractMySub1", sequenceName = "AbstractMySub1_id")
    @GeneratedValue(generator = "AbstractMySub1")
    @Column(precision=5)
    private int id;

    @ManyToOne(cascade={CascadeType.PERSIST,CascadeType.MERGE, CascadeType.REFRESH})
    private MySub1 mysub1;

    ...
}


The relationship sub-classes:

Code:
@Entity
@DiscriminatorValue("I")
public class IncludedMySub1 extends AbstractMySub1 {

}

@Entity
@DiscriminatorValue("E")
public class ExcludedMySub1 extends AbstractMySub1 {

}


I got the following error:

Code:

[hibernatetool] Problems in creating a configuration for JPA. Have you remembered to add hibernate EntityManager jars to the classpath ?
[hibernatetool] java.lang.reflect.InvocationTargetException
[hibernatetool] javax.persistence.PersistenceException: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: ExcludedMySub1.mysub1 in MySub1.excludedSub1
[hibernatetool] org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: ExcludedMySub1.mysub1 in MySub1.excludedSub1
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error executing ant tasks

Embedded error: Problems in creating a configuration for JPA. Have you remembered to add hibernate EntityManager jars to the classpath ?
mappedBy reference an unknown target entity property: ExcludedMySub1.mysub1 in MySub1.excludedSub1
[INFO] ------------------------------------------------------------------------
[INFO] Trace
org.apache.maven.lifecycle.LifecycleExecutionException: Error executing ant tasks
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:583)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:499)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:478)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:330)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:291)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:142)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:336)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:129)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:287)
        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.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
        at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
        at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
        at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.apache.maven.plugin.MojoExecutionException: Error executing ant tasks
        at org.apache.maven.plugin.antrun.AbstractAntMojo.executeTasks(AbstractAntMojo.java:114)
        at org.apache.maven.plugin.antrun.AntRunMojo.execute(AntRunMojo.java:83)
        at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:451)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:558)
        ... 16 more
Caused by: Problems in creating a configuration for JPA. Have you remembered to add hibernate EntityManager jars to the classpath ?
        at org.hibernate.tool.ant.JPAConfigurationTask.createConfiguration(JPAConfigurationTask.java:57)
        at org.hibernate.tool.ant.ConfigurationTask.getConfiguration(ConfigurationTask.java:54)
        at org.hibernate.tool.ant.HibernateToolTask.getConfiguration(HibernateToolTask.java:302)
        at org.hibernate.tool.ant.Hbm2DDLExporterTask.execute(Hbm2DDLExporterTask.java:45)
        at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:186)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
        at org.apache.tools.ant.Task.perform(Task.java:364)
        at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:64)
        at net.sf.antcontrib.logic.IfTask.execute(IfTask.java:197)
        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.apache.tools.ant.TaskAdapter.execute(TaskAdapter.java:123)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
        at org.apache.tools.ant.Task.perform(Task.java:364)
        at org.apache.tools.ant.Target.execute(Target.java:341)
        at org.apache.maven.plugin.antrun.AbstractAntMojo.executeTasks(AbstractAntMojo.java:108)
        ... 19 more
Caused by: java.lang.reflect.InvocationTargetException
        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.hibernate.tool.ant.JPAConfigurationTask.createConfiguration(JPAConfigurationTask.java:43)
        ... 36 more
Caused by: javax.persistence.PersistenceException: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: ExcludedMySub1.mysub1 in MySub1.excludedSub1
        at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:258)
        ... 41 more
Caused by: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property:ExcludedMySub1.mysub1 in MySub1.excludedSub1
        at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:552)
        at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:517)
        at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:43)
        at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1136)
        at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:316)
        at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1121)
        at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1269)
        at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:150)

        at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:888)
        at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:186)
        at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:246)
        ... 41 more
[INFO] ------------------------------------------------------------------------


We need help to find out what is the cause of this error and how to resolve it. Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 04, 2008 1:18 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Any luck finding a fix?

_________________
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.