jQuery in Action, 2nd edition
The moose likes Object Relational Mapping and the fly likes Hibernate mapping question Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Object Relational Mapping
Reply Bookmark "Hibernate mapping question" Watch "Hibernate mapping question" New topic
Author

Hibernate mapping question

Andreas Jonsson
Greenhorn

Joined: Jul 15, 2006
Posts: 4
Hi.

I'm trying to create a mapping file for FAULT_RECORD. Any FAULT_RECORD links to an ERROR_TEXT(wich primary key consists of device_group and errorcode),
and to be able to connect them I have to go through DEVICE in order to get the device_group.

I have been searching on various forums but havn't been able to find a similar example, partly because I'm not sure what(keywords) to search for.

If anyone could come up with a solution, or at least point me in the right direction I'd be VERY happy

/Andreas

Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 16622

Can you include the cardinality between the tables?

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Andreas Jonsson
Greenhorn

Joined: Jul 15, 2006
Posts: 4
Of course Sorry.. I've updated the picture/diagram in my first post.

/Andreas
Scott Johnson
Ranch Hand

Joined: Aug 24, 2005
Posts: 518
Andreas,

Is the cardinality between device and fault_record really 1 to many?

Both tables have the same primary key, do they not?

The easiest way to map this might be to ignore the relationship between fault_record and error_text. To get the error_text, get the device entity from the fault_record and then retrieve the error_text from the device. To limit the error_text to the desired entity, use a filter. (See Hibernate Reference Sec 10.4.2.)

Scott
[ July 16, 2006: Message edited by: Scott Johnson ]
Andreas Jonsson
Greenhorn

Joined: Jul 15, 2006
Posts: 4
Originally posted by Scott Johnson:
Andreas,

Is the cardinality between device and fault_record really 1 to many?

Both tables have the same primary key, do they not?

The easiest way to map this might be to ignore the relationship between fault_record and error_text. To get the error_text, get the device entity from the fault_record and then retrieve the error_text from the device. To limit the error_text to the desired entity, use a filter. (See Hibernate Reference Sec 10.4.2.)

Scott

[ July 16, 2006: Message edited by: Scott Johnson ]


Hi, and thank you for your reply!
Yes it is a one-to-many relationship between DEVICE and FAULT_RECORD. They don't have the same primary key. The DEVICE primary key exists in FAULT_RECORD only as a foreign key.

A FAULT_RECORD needs to be connected to ERROR_TEXT to get the text belonging to a fault. Both ERROR_TEXT and DEVICE are static tables( correct term? ) only used to retrieve the text for a fault.

The problem is that a FAULT_RECORD knows what DEVICE who triggered the fault, but ERROR_TEXTs is only concerned about device_group, and FAULT_RECORD knows nothing about device_groups.

I will now check out the filters you mentioned. Thanks again!

/Andreas
[ July 17, 2006: Message edited by: Andreas Jonsson ]
Scott Johnson
Ranch Hand

Joined: Aug 24, 2005
Posts: 518
They don't have the same primary key.


Ok, I was thinking that fault_record.id was the same as device.id, which I see now that it's not...
Andreas Jonsson
Greenhorn

Joined: Jul 15, 2006
Posts: 4
Originally posted by Scott Johnson:
Andreas,

To limit the error_text to the desired entity, use a filter. (See Hibernate Reference Sec 10.4.2.)

Scott

[ July 16, 2006: Message edited by: Scott Johnson ]

Hi again. I've read some about filters now and I'm not so sure it is what I'm looking for when it comes to this mapping thing, but I have already found other places I can use it

/Andreas
 
 
subject: Hibernate mapping question
 
Threads others viewed
Try these games...
Hibernate Mapping Files Ignored
Remote Client - Annotation lookup possible?
Multiple subclasses, one superclass in Hibernate.
Requested resource not available
MyEclipse, The Clear Choice