-->
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: complex inheritance problem
PostPosted: Tue Mar 03, 2009 11:15 am 
Newbie

Joined: Tue Mar 03, 2009 9:32 am
Posts: 7
Hello,

This is my case: In my company we are rebuilding our system and
I have 2 different DB tables, one is a legacy table I want to support and the other is a new table.
Both tables represent the same entity, but with some columns renamed/ added/ removed.

My solution was to create one abstract class (lets call it Item) which I annotated with the following:

@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class Item

@Id
@Column(name = "id")
private Long id;

@Column(name = "name")
private String name;


I then created two more classes extending this abstract class:

@Entity
@Table(schema = "schema1", name = "TABLE_V1")
@AttributeOverrides(
{
@AttributeOverride(name = "id", column = @Column(name = "id_v1")),
@AttributeOverride(name = "name", column = @Column(name = "name_v1"))
})
public class ItemV1 extends Item



and -

@Entity
@Table(schema = "schema2", name = "TABLE_V2")
public class ItemV2 extends Item



Item defines the common attributes from both tables (id and name).

ItemV2 is meant for the new DB table and is currently not having properties which are not already defined in the abstract Item.
ItemV1 should support the legacy table. In the future I expect not to use it anymore, with no affection over my design.

My problem is I can't override the column names using the @AttributeOverrides annotation in ItemV1.

Can anyone tell me how to overcome this obstacle or think of a better way to implement this?

_________________
Regards,
Uri Bar


Top
 Profile  
 
 Post subject: AttributeOverrides works only for 1 level inheritance ?
PostPosted: Fri Apr 10, 2009 1:10 pm 
Newbie

Joined: Thu Apr 09, 2009 6:08 pm
Posts: 2
I have a similar issue.

Apparently I cannot override an existing AttributeOverrides, can I ?

In the example below the AttributeOverrides does not work. I keep getting a message saying that the address property has been already mapped.

This is a simplified version of my model:

public class A {

protected Address adress;

}


public class B extends A{

@Embedded
@AttributeOverride(name="country", column = @Column(name="b_country_code") ),
{
return address;
}

}

public class C extends B {

@Embedded
@AttributeOverride(name="country", column = @Column(name="b_country_code") ),
public Address getAdress
{
return address;
}

}

@Embeddable
public class Address{

String country

}

Thanks for any ideas,

Ken


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.