Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate mapping question

 
Andreas Jonsson
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you include the cardinality between the tables?

Mark
 
Andreas Jonsson
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course Sorry.. I've updated the picture/diagram in my first post.

/Andreas
 
Scott Johnson
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic