-->
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.  [ 8 posts ] 
Author Message
 Post subject: AttributeOverride ignored when used with @Inheritence
PostPosted: Thu Apr 26, 2007 4:55 am 
Newbie

Joined: Sat Mar 10, 2007 2:43 am
Posts: 4
Hibernate version: 3.2.3.ga
Hibernate Entity version: 3.3.1.ga

Hi,

I am wanting to do the following:

Code:
@Entity
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
public abstract class Parent implements Serializable {
    @Id
    private Long    recordNo;
}


@Entity
@AttributeOverride(name="recordNo", column=@Column(name="CHILD1_RECORD_NO"))
public class Child1 extends Parent {

}

@Entity
@AttributeOverride(name="recordNo", column=@Column(name="CHILD2_RECORD_NO"))
public class Child2 extends Parent {

}



Attempting to access a child results in the following SQL error implying the @AttributeOveride was ignored:
Caused by: java.sql.SQLException: ORA-00904: "CHILD1_"."RECORD_NO": invalid identifier

The entire DB schema is designed such that the primary key on each table is a single column named TABLENAME_RECORD_NO so I definitely need to be able to override the column name in the children classes. Renaming columns to workaround this issue is not an option.

If I use a MappedSuperclass instead, the @OverrideAttribute annotation is honoured but I become limited in my use of HQL. ie. I can no longer write generic HQL such as "select parent from Parent as parent where parent.recordNo = :recordNo"


Is this a bug or a limitation? It seems a bit odd that the @OverrideAttribute on an @Id column works with a @MappedSuperclass but not with @Inheritence.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 01, 2007 3:35 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Today, TABLE-PER_CLASS cannot override the column names unfortunately.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 07, 2007 4:37 am 
Newbie

Joined: Sat Mar 10, 2007 2:43 am
Posts: 4
Is this intended functionality or a bug that needs to be raised?

It seems a bit odd that Hibernate is dictating the naming convention of my database.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 14, 2007 11:06 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
This is the expected behavior.

But a feature request makes sense.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 18, 2007 1:46 am 
Newbie

Joined: Sat Mar 10, 2007 2:43 am
Posts: 4
I have raised an JIRA request.


http://opensource.atlassian.com/project ... e/HHH-2619


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 06, 2007 9:49 pm 
Newbie

Joined: Tue Nov 06, 2007 9:29 pm
Posts: 2
Location: Perth, WA
Is the same true of
Code:
InheritanceType.JOINED
?

I have

Code:
@Entity
@Table(name = "PERSON")
@Inheritance(strategy = InheritanceType.JOINED)
public class PersonImpl {
    @Column(name = "NAME") private String name;
}

@Entity
@Table(name = "SPECIAL_PERSON")
public class SpecialPersonImpl  extends PersonImpl {
    // Some sub class
}

@Entity
@Table(name = "PERSON_VIEW")
@AttributeOverride(name = "name", column = @Column(name = "NAME"))
public class PersonViewImpl extends PersonImpl {
    // Where PERSON_VIEW has the same schema as PERSON but different
    // data in it's NAME column
}


And when I select from PersonViewImpl I get:

Code:
select this_.ID as ID0_0_, this_1_.AGE as AGE0_0_, this_1_.NAME as NAME0_0_ from PERSON_VIEW this_ inner join PERSON this_1_ on this_.ID=this_1_.ID


Hibernate is not using the NAME column from PERSON_VIEW, just from PERSON.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 09, 2007 6:46 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
What you want doe not make sense from a DB schema point of view :)

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Re:
PostPosted: Wed May 06, 2009 3:59 pm 
Newbie

Joined: Wed Jun 06, 2007 9:14 am
Posts: 14
emmanuel wrote:
This is the expected behavior.

But a feature request makes sense.


Does Hibernate already have a solution or a workaround for this? I'm running on the same issue.

These are my mappings:

Parent class:
Code:
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class Pessoa
{
   private String matricula;
   private String nome;
   
   Pessoa()
   {
   }
   
   @Id
   public String getMatricula()
   {
      return matricula;
   }

   public void setMatricula(String matricula)
   {
      this.matricula = matricula;
   }

   public String getNome()
   {
      return nome;
   }

   public void setNome(String nome)
   {
      this.nome = nome;
   }
}

Subclass:
Code:
@Entity
@Table(name = "GE_FUNCIONARIOS")
public class FuncionarioNovo extends Pessoa
{
}

Subclass:
Code:
@Entity
@Table(name = "ALUCUR")
@AttributeOverrides({
   @AttributeOverride(name = "matricula", column = @Column(name = "CDALUCUR")),
   @AttributeOverride(name = "nome", column = @Column(name = "NUGRA"))
})
public class Aluno extends Pessoa
{
}


The generated query:

Code:
select pessoa0_.matricula as matricula0_, pessoa0_.nome as nome0_, pessoa0_.clazz_ as clazz_ from ( select nome, matricula, 1 as clazz_ from GE_FUNCIONARIOS union select nome, matricula, 2 as clazz_ from ALUCUR ) pessoa0_ where pessoa0_.matricula=?


and the error:
Code:
com.microsoft.sqlserver.jdbc.SQLServerException: Invalid column name 'nome'.



Thank you.

Marcos


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.