-->
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.  [ 5 posts ] 
Author Message
 Post subject: @AttributeOverride doesn't seem to work
PostPosted: Thu Sep 11, 2008 8:59 pm 
Beginner
Beginner

Joined: Fri Aug 05, 2005 3:36 am
Posts: 28
I've got a JOINED subclass that uses @AttributeOverride to override the name of the column containing the id, but in the generated query that joins the tables, the base class column name appears everywhere.

Hibernate Annotations 3.4.0GA, Windows XP, Oracle 10g.

Here's the base class:

Code:
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorColumn(name="entityType")
@Table(name="BASE")
public abstract class Base {
   
   @Id
   @Column(name="BASE_ID")
   @GeneratedValue
   private Long id;
...
}


and here's the subclass:

Code:
@Entity
@Table(name="SUBCLASS1")
@DiscriminatorValue("SUBCLASS1")
@AttributeOverride(name="id", column=@Column(name="SUB_ID"))
public class Subclass1 extends Base {
...
}


Here's the DAO method that fetches all Subclass1 entities:

Code:
@SuppressWarnings("unchecked")
public List<Client> getAllSubclass1() {
     List list = getSession()
     .createCriteria(Subclass1.class)
     .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)
     .addOrder(Order.asc("name"))
     .setFetchMode("anassociation", FetchMode.LAZY)
     .setFetchMode("anotherassociation", FetchMode.LAZY)
     .list();
return list;
   }



Here's the query that is generated:
Code:
SELECT   this_.base_id AS base1_0_0_,
         this_1_.discriminator AS discrimi2_0_0_, this_.NAME AS name1_0_,
         this_.originalid AS originalid1_0_
    FROM subclass1 this_ INNER JOIN base this_1_
         ON this_.base_id = this_1_.base_id
ORDER BY this_.NAME ASC


And the error:

Code:
Caused by: java.sql.SQLException: ORA-00904: "THIS_"."BASE_ID": invalid identifier


The query is wrong; the first field in the SELECT ought to be "this_.sub_id", and the left side of the ON ought to be "this_.sub_id" also.

Any ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 15, 2008 9:06 am 
Newbie

Joined: Wed May 21, 2008 11:52 am
Posts: 5
It seems to be impossible to rename column names in subclasses by the help of @AttributeOverride annotations. You might consider to vote on bug http://opensource.atlassian.com/project ... e/HHH-2619

-- Frank


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 15, 2008 3:02 pm 
Beginner
Beginner

Joined: Fri Aug 05, 2005 3:36 am
Posts: 28
I guess so. Apparently @AttributeOverride is only meant for use with a @MappedSuperclass or an embedded object. I think it's a JPA thing.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 16, 2008 1:48 am 
Newbie

Joined: Wed May 21, 2008 11:52 am
Posts: 5
Quote:
I think it's a JPA thing.


Well, the JSR-220-persistence specification text does indeed use @AttributeOverride only for @MappedSuperclass and @Embedded. But I cannot find a line in the specification that says, @AttributeOverride is restricted to these use cases.

OpenJPA on the contrary lets you rename primary key columns as well as basic columns in ordinary subclasses with @AttributeOverride.

-- Frank


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 27, 2008 12:39 pm 
Newbie

Joined: Wed May 21, 2008 11:52 am
Posts: 5
Code:
@PrimaryKeyJoinColumn(name="SUB_ID")
public class Subclass1 extends Base {

will do.

-- Frank


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