-->
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: JPA: Identical tables mapping
PostPosted: Wed Mar 12, 2008 3:15 pm 
Newbie

Joined: Tue Jan 29, 2008 1:30 pm
Posts: 9
Hi all,

I have the strangest schema: I have identical tables where only the name of the table is different. The purpose of the copy table is to move data from the main table, (don't ask...) and store it in the copy table instead. Problem is, I need to have a perfect replica of the main table, including relations (I also have copies of the relation tables, which include 1-N, N-1, etc).

Obviously, I do not want to replicate the properties and mapping for all entities. I have tried to use the table_per_class hierarchy but I couldn't perform polymorphic jpa queries.

I mapped the superclass this way:

Code:
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class GenericFulfillmentRequestEJB implements java.io.Serializable {
(...) //class properties
}


And the child classes this way:
Code:
@Entity
@Table(name = "OMP_FULFILLMENT_REQUEST")
public class FulfillmentRequestEJB extends GenericFulfillmentRequestEJB  implements java.io.Serializable{
//zero properties
}


Problem is, my Generic classes have also other Generic classes in 1-n and n-1 relations, and it seems that I can't get polymorphic queries to work. If I query the superclass, hibernate can't distinguish between the instances, altough the query reveals a union and a correct clazz_ column to differentiate instance types. The hibernate docs state that joins do work if I use the union-class strategy, which is equivalent to jpa's table_per_class strategy.

Is this possible with minimum effort? I want to be able to do polymorphic queries, besides not replicating same attributes for the 2 entities.

Thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 13, 2008 12:23 pm 
Beginner
Beginner

Joined: Thu Jan 31, 2008 7:09 am
Posts: 34
Hi, I had something similar.

I ended up using the
@entity
@Inheritance(strategy = InheritanceType.JOINED)

that way you can do what you want, and made the parent class abstract.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 14, 2008 11:26 am 
Newbie

Joined: Tue Jan 29, 2008 1:30 pm
Posts: 9
Hi,

Thanks for the info. The docs seem to indicate that JOINED inheritance is normally used when you have a "super table", ie, for vertical inheritance. My problem is that my super class will also have other properties that are themselves abstract:
Code:
abstract class AbstractProcess {

     public Set<AbstractTaxPayer> getAbstractTaxPayers(){
     }
     //(...)
}

abstract class AbtsractTaxPayer {
//(...)
}

@Entity
@Table(name="REGULAR_P")
@Inheritance(strategy=InheritanceType.JOINED)
class RegularProcess extends AbstractProcess {
//(...)
}


@Entity
@Table(name="FOREIGN_P")
@Inheritance(strategy=InheritanceType.JOINED)
class ForeignProcess extends AbstractProcess {
//(...)
}

@Entity
@Table(name="REGULAR")
@Inheritance(strategy=InheritanceType.JOINED)
class RegularTaxPayer extends AbstractTaxPayer {
//(...)
}

@Entity
@Table(name="FOREIGN")
@Inheritance(strategy=InheritanceType.JOINED)
public class Contract
class ForeignTaxPayer extends AbstractTaxPayer {
//(...)
}


I tried this with TABLE_PER_CLASS strategy (the annotation goes forthe abstract classes), but my polymorphic queries were giving me invalid results.


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.