-->
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.  [ 1 post ] 
Author Message
 Post subject: Mix TABLE_PER_CLASS and SINGLE_TABLE
PostPosted: Tue Dec 02, 2008 10:43 am 
Newbie

Joined: Sun May 14, 2006 7:31 am
Posts: 10
hi All ,

First of all here is my hibernate config :
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate</artifactId>
<version>3.2.6.ga</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.3.1.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search</artifactId>
<version>3.0.1.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>3.0.0.ga</version>
</dependency>

I have a problem defining this kind of hierarchy :
The top class is abstract and is like that :
Code:
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class PersistentObject
{}


One of its subclasses is defined like that, note the SINGLE_TABLE :
Code:
@Entity
@Table(name = "CATALOG_ITEM",
        uniqueConstraints = {@UniqueConstraint(columnNames = {"NAMEQUALIFIER", "NAME"})}
)
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "CATALOG_ITEM_TYPE", discriminatorType = DiscriminatorType.INTEGER)
@DiscriminatorValue(Constants.DISCRIMINATOR_CATALOGITEM)
public class CatalogItemEntity extends PersistentObject {
}


The first issue is that the session factory isn't able to find NAME and NAMEQUALIFIER, which are both declared in subclass of CatalogitemEntity. This works when PersistentObject isn't an Entity => no TABLE_PER_CLASS.

If I comment the constraint out, the session factory starts correctly but while executing queries based on a subclass (WebMapServiceEntity) of CatalogItemEntity, I get errors like :
Quote:
Caused by: java.sql.BatchUpdateException: L'élément du batch 0 insert into WebMapServiceEntity (IDENTIFIER, OPT_NAME, OBJECTTYPE, REG_DATE, TAGS, ABSTRACT, NAMEQUALIFIER, NAME, TITLE, OWS_CONTACT, OWS_RESOURCEURI, OWS_SERVICEFEES, OWS_SERVICEVERSION, PERSISTENT_OBJECT_ID) values (guid:f803076f0a2c7ea601ee9cc37840020c, f803076e0a2c7ea600404eb28114be89, NULL, 2008-12-02 15:03:47.438000 +01:00:00, NULL, NULL, http://www.erdas.com/f803076e0a2c7ea601ee9cc347ede9e1, f803076e0a2c7ea600404eb28114be89, NULL, NULL, http://www.erdas.com/f803076e0a2c7ea601ee9cc347ede9e1, NULL, 1.0, 8aacfe261df802cd011df803076f00ef)


It seems that Hibernate isn't able to discover the mixed hierarchy.

Is there a way to achieve this ?

For a matter of compleness, I've added the PersistentObject as an Entity to be able to query on PersistentObject polymorphically without having as many sub queries as tables underneath PersistentObject, but using the UNION.

Thanks a lot.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.