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]