wood burning stoves 2.0*
The moose likes EJB and other Java EE Technologies and the fly likes Map 2 CMP Entity Beans to 1 table? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Map 2 CMP Entity Beans to 1 table?" Watch "Map 2 CMP Entity Beans to 1 table?" New topic
Author

Map 2 CMP Entity Beans to 1 table?

Russ R
Greenhorn

Joined: Jun 06, 2005
Posts: 6
Hello all,

I'm working with a legacy database table that cannot be changed. I need to associate each DAY with a set of TIMES.

Here's the structure:

Table Name: DAY

day_id open_time close_time sequence
------ -------- ---------- --------
MONDAY 06:00 AM 08:00 PM 1
MONDAY 10:00 PM 10:30 PM 2
TUESDAY 06:00 AM 08:00 PM 1
WEDNESDAY 06:00 AM 07:00 PM 1
THURSDAY 06:00 AM 04:00 PM 1
THURSDAY 10:00 PM 10:30 PM 2

-The primary key is (day_id, sequence)

Here is what I have so far:

-I think there should be 2 entity beans (DayBean, TimeBean); DayBean has a Collection of TimeBeans
-There is a one-to-many relation from DayBean to TimeBean.

Has anyone else encountered a recursive table as such? Ideas?


Russ<br />SCJP, SCWCD, SCBCD
Tim West
Ranch Hand

Joined: Mar 15, 2004
Posts: 539
I'm no expert, but if I were you I'd use one bean for the entire table, but have whatever structure is most logical in your value objects. Then, do the mapping in the getVO/setVO methods on your bean. I'd imagine it'll be much easier to do the mapping there.

You couldn't use CMR to do your daybean/timebean mapping, since (AFAIK) all CMR implementations require two tables with a foreign key-type attribute on one or both of them. It seems to me that the basic usual philosophy 'one entity bean maps onto one table'.

More on Sun's view of Value Objects is here, though I'm not sure that'll be of that much use.


-Tim
Russ R
Greenhorn

Joined: Jun 06, 2005
Posts: 6
Thanks Tim. I will most likely just use a Session Bean w/JDBC and populate 2 VO's as you suggest.

Any expert EJB designers with suggestions?

Tim West
Ranch Hand

Joined: Mar 15, 2004
Posts: 539
You could give Sun's Java forums a go if no-one here is forthcoming.

And good ol' Mastering EJB2 book is available free on the 'net, though I'm not sure it'd be a huge amount of help in this situation.


-Tim
Russ R
Greenhorn

Joined: Jun 06, 2005
Posts: 6
Mastering EJB 2nd edition has a section on 'Dealing w/ Legacy data', but no suggestions for this particular table design.
Purushoth Thambu
Ranch Hand

Joined: May 24, 2003
Posts: 425
Can't we use ejbSelectXXX method to get the TIMES details ? this method can return a collection of attributes of entity bean.
Russ R
Greenhorn

Joined: Jun 06, 2005
Posts: 6
I think that is a very good suggestion.

Using selectXXX gives me the abililty to manage the relationships without using CMR.

thanks alot!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Map 2 CMP Entity Beans to 1 table?
 
Similar Threads
oracle date between
Cron Expression for "After Every 30 days at midnight" ?
Book for SCBCD5.0 Beta
How to identify Auth method NTLMv1 or NTLMv2
[India]Gone days