File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Parent class id value instead of child's id used incorrectly for querying Set assoc. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Parent class id value instead of child Watch "Parent class id value instead of child New topic
Author

Parent class id value instead of child's id used incorrectly for querying Set assoc.

M. Saeed
Greenhorn

Joined: Sep 24, 2008
Posts: 5
Apologies if this is re post. I have three classes A, B(subclass of A), and C.
B has a Set of elements of C.
In the database there are three corresponding tables A_TABLE, B_TABLE, and C_TABLE, and an additional view B_VIEW which is what B is mapped to(instead of B_TABLE, because the view has data from additional tables). On inserts into B_VIEW, a trigger in the database inserts a row into B_TABLE using a sequence. The code and mapping for A&B has existed before as did all the database tables and views. I am trying to add a set mapping for C.

While the data is inserted into C_TABLE correctly (due to B lacking an Id, there is an insert of B only followed by update of B with the set of C attached ), the issue is that on the read path (load collections from database), hibernate does not load anything because in the criteria query it tries to use the value of aId (instead of value of bId) in the query, even though the column name is correct. The issue arises because B is mapped using a <join> without an entity id, and hibernate has all the B instances at runtime identified with aId.

My Question is whether there is a way to fix this, perhaps by telling hibernate that it should use bId as the foreign key instead of aId during the load. I know this is twisted, but the code has existed for a long time. TIA for any suggestions and help.

Query at runtime:


Java classes:


Hibernate Mappings

A.hbm.xml



B.hbm.xml



C.hbm.xml
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Parent class id value instead of child's id used incorrectly for querying Set assoc.
 
Similar Threads
Hibernate generating queries with duplicate columns
JPA self refrencing relationship problem...HELP Needed
Hibernate Criteria can't create joins for Embedded objects
Composite foreign key mapping in Hibernate 3 using JPA
Mapping a class as component with array type field