-->
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: ManyToOne field binding to Abstract Entity class
PostPosted: Thu Sep 14, 2006 12:24 pm 
Newbie

Joined: Thu Sep 14, 2006 12:08 pm
Posts: 19
I am using Java Persistence API (JPA) using hibernate-entitymanager-3.2.0.CR1.

I am migrating my application from using JDBC to using Java Persistence
API. The schema is fixed by an ISO standard (cannot be changed) and
represents the relational mapping of an OO model with inheritance semantics.

A simplified version of the inheritance Model is shown here:

http://ebxmlrr.sourceforge.net/tmp/Simp ... iagram.png

The UML diagram is mapped to the schema such that:

-Each leaf class (Oragnization, and Classification) has its own table (TABLE_PER_CLASS)

-There is no table defined for the base class RegistryObject

-All base class attributes are duplicated in the leaf class table

-A View is defined for the base class RegistryObject which allows for
querying at the base class level.

-The base class has a collection of composed object (but not embedded
from a relational standpoint) Classification which uses a foreign key to
join with the parent Leaf class (Organization or Classification).

A simplified version schema is as follows:

CREATE TABLE Organization (
id VARCHAR(256) NOT NULL PRIMARY KEY,
...
);

CREATE TABLE Classification (
id VARCHAR(256) NOT NULL PRIMARY KEY,
--Foreign key to parent RegistryObject being classified by this object
classifiedObject VARCHAR(256) NOT NULL,
...
);

CREATE VIEW RegistryObject (
--Base class Attributes
id,
...
) AS
SELECT
id,
...
FROM Organization
UNION ALL
SELECT
id,
...
FROM Classification

The Entity classes I have defined for above schema are as follows:

@Entity
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
public abstract class RegistryObject implements Serializable {

@Id
@Column(name = "ID", nullable = false)
protected String id;

@OneToMany (mappedBy="classifiedObject",
cascade={CascadeType.REMOVE, CascadeType.PERSIST})
protected Collection<Classification> classifications;

....accessor methods....
}

@Entity
@Table(name = "ORGANIZATION")
public class Organization extends RegistryObject {
...
}

@Entity
@Table(name = "CLASSIFICATION")
public class Classification extends RegistryObject {
@ManyToOne
@JoinColumn(name = "CLASSIFIEDOBJECT", referencedColumnName = "id", table = "RegistryObject", nullable = false)
private RegistryObject classifiedObject;


...
}

The Problem:

When I run a junit test to test an insert of an Organization with an associated set of Classification instances I get the following stack trace. I am assuming that I can use an abstract EntityClass as the target of a ManyToOne relationship in a stratgey=InheritanceType.TABLE_PER_CLASS. What am I doing wrong?

Thanks for your help.

Hibernate version:
3.2 cr2, May 5, 2006
hibernate-entitymanager-3.2.0.CR1

Full stack trace of any exception that occurs:

...
INFO: Binding Named query: Classification.findByNoderepresentation => SELECT c FROM Classification c WHERE c.noderepresentation = :noderepresentation
Sep 14, 2006 10:40:36 AM org.hibernate.cfg.annotations.EntityBinder bindTable
INFO: Bind entity org.freebxml.omar.server.persistence.rdb.entitybean.Classification on table CLASSIFICATION
at org.freebxml.omar.server.persistence.rdb.SQLPersistenceManagerTest.testInsert(SQLPersistenceManagerTest.java:54)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
Caused by: org.hibernate.AnnotationException: Cannot find the expected secondary table: no RegistryObject available for org.freebxml.omar.server.persistence.rdb.entitybean.Classification
at org.hibernate.cfg.Ejb3Column.getJoin(Ejb3Column.java:293)
at org.hibernate.cfg.Ejb3Column.getTable(Ejb3Column.java:272)
at org.hibernate.cfg.AnnotationBinder.bindManyToOne(AnnotationBinder.java:1765)
at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1250)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:699)
at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:353)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:265)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1034)
at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1015)
at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:154)
at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:751)
at org.hibernate.ejb.Ejb3Configuration.createFactory(Ejb3Configuration.java:151)
at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:205)
... 20 more


Name and version of the database you are using:
HSQLDB

Thanks for your help.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 15, 2006 7:23 am 
Newbie

Joined: Thu Sep 14, 2006 12:08 pm
Posts: 19
This problem was simple to fix. Just not specify 'table = "RegistryObject"'
in the JoinColumn annotation (duh):


Old:

@Entity
@Table(name = "CLASSIFICATION")
public class Classification extends RegistryObject {
@ManyToOne
@JoinColumn(name = "CLASSIFIEDOBJECT", referencedColumnName = "id", table = "RegistryObject", nullable = false)
private RegistryObject classifiedObject;
...
}

New:

@Entity
@Table(name = "CLASSIFICATION")
public class Classification extends RegistryObject {
@ManyToOne
@JoinColumn(name = "CLASSIFIEDOBJECT", referencedColumnName = "id", nullable = false)
private RegistryObject classifiedObject;
...
}

Does this mean I get a credit point ;-)


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.