-->
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: Unable to find column and some joined inheritance troubles
PostPosted: Wed Mar 19, 2008 9:44 am 
Newbie

Joined: Tue Mar 11, 2008 7:52 am
Posts: 5
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.2.6

Name and version of the database you are using: SQL Server 2005


Hi all...!

First of all, lots of thanks to he Hibernate team, up the good work..! :-D

Me and my legacy database and domain model are becoming great friends... :-P

I have this situation:

Code:
@Entity
@Table(name = "TABLE_A")
@AttributeOverride( name="id", column = @Column(name="A_ID") )
public Class A extends from BaseModel {

    // id is inherited from BaseModel and is a Integer
    // BaseModel implements Serializable

    ...
}

@Entity
@Table(name="TABLE_B")
@AttributeOverride( name="id", column = @Column(name="B_ID") )
@PrimaryKeyJoinColumn(name="A_ID", referencedColumnName="A_ID")
public class B extends A {

    // A has a id since it extends from A and therefore from BaseModel

   @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)   
   @JoinTable(name="B_C", joinColumns = @JoinColumn(name="B_ID",                                 referencedColumnName="B_ID"),
        inverseJoinColumns = @JoinColumn(name="C_ID", referencedColumnName="C_ID")
         )
   private Set<C> lotsOfC;
}


C is another class that is not important here - or so I think. This extrange mapping is because of a legacy database:

Code:
TABLE A
-----------
A_ID (PK)


TABLE_B
------------
B_ID (PK)
A_ID (FK references A.A_ID)


B_C
-----
B_ID (PK)
B_ID (PK)


I'ts pretty clear the database says there is no inheritance between A and B, but a "B has an A" relation. But again I cannot modify my classes. The only thing I can do Is to play with the annotations hoping there is one that solves my problem.

The problem is that when I execute a JUnit test case, Hibernate throws an exception like this:

Code:
org.hibernate.MappingException: Unable to find column with logical name: B_ID in org.hibernate.mapping.Table(B) and its related supertables and secondary tables


Obviously I don't understand the problem. The B_ID column does exists in table B, and is annotated in the B class as the property "id".

Which is the correct mapping? In few words: I do need help!

Thank you all.




[/code]


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.