-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: How to map a table with 15 qty columns to a one to many rel?
PostPosted: Thu Sep 17, 2009 11:26 am 
Beginner
Beginner

Joined: Tue Mar 13, 2007 8:26 am
Posts: 25
Hello all,

I'm trying to map a legacy database, a very bad designed one by the way, to classes. What I want to do is map the database to classes, but I don't want to make the classes as wrong as the database and I'm wondering if it's possible to do what I describe bellow.

I've a Stock table which has 15 fields related to quantities, like this:
Code:
create table STOCK (
  ID INTEGER PRIMARY KEY,
  PRODUCT_ID INTEGER,
  COLOR_ID INTEGER,
  QUANT_01 DECIMAL(12,2),
  QUANT_02 DECIMAL(12,2),
  -- REPEAT UNTIL THE 15
  QUANT_15 DECIMAL(12,2)
);


Each quantity column represents the quantity of a kind, for example product "shoes" quant_01 means the quantity for size 7 and quant_02 means size 8.

I'm creating a new system that needs to use this table and I'd like to create classes without this terrible model. For example I'd like to create the following classes:

Code:
class Stock {
    private int id;
    private Produtct product;
    private Color color;
    private Set<StockQuantity> quantities;
}

class StockKind { // the shoes size
    private int id;
    private String description;
}

class StockQuantity {
   private Stock stock;
   private StockKind kind;
   private BigDecimal quantity;
}


I was thinking in a way to map the fields to StockQuantity and I'd like to know if anybody has any tips about how to accomplish this using Hibernate. What do you think, should I do this, any other ideas?

Regards

_________________
---
Felipe Marin Cypriano


Top
 Profile  
 
 Post subject: Re: How to map a table with 15 qty columns to a one to many rel?
PostPosted: Thu Sep 17, 2009 5:05 pm 
Beginner
Beginner

Joined: Tue Mar 13, 2007 8:26 am
Posts: 25
I made an almost-diagram to make this problem simpler to understand, see:

Image

This image shows an example of row the data is in the database and how it should be in the classes. Each quant_?? column generates a new StockQuantity and StockKind object, the Stock object holds a collection with it's own quantities (StockQuantity class).

Is this possible to do using hibernate?

_________________
---
Felipe Marin Cypriano


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.