-->
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.  [ 3 posts ] 
Author Message
 Post subject: CompoundKey/Mapping problem
PostPosted: Wed Mar 03, 2010 5:35 am 
Newbie

Joined: Wed Mar 03, 2010 5:04 am
Posts: 2
I have an entity Call containing an ItilStatus:

Code:
@Entity
public class Call {

   @Id
   private int id;

   private ItilStatus itilStatus;

   ...
   
   More fields
   
}
   


ItilStatus does not have its own table, but the possible values are found in a table with 5 columns:

Code:
----------------------------------------------------------------------
| table_name | column_name | column_type | enum_value | enum_label |
----------------------------------------------------------------------


The first four columns make up the compound primary key - so I have created a CompoundKey class:

Code:
@Embeddable
public class EnumCompoundKey implements Serializable {

    private String tableName;

    private String columnName;

    private int columnType;

    private int enumValue;

   ...
   
    4-param contructor, getters, setters, hashCode() and equals()
   
}


However, for ItilStatus, the 3 first fields are always set to 'calls', 'itilstatus' and '14'.

How should this 'static' relationship be reflected in the ItilStatus class?

Code:
@Entity
public class ItilStatus {

    @Id
    private EnumCompoundKey id;

    private String label;

    public EnumCompoundKey getId() {
        return id;
    }

    public void setId(EnumCompoundKey id) {
        this.id = id;
    }

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }

}


Is my approach completely wrong?


Top
 Profile  
 
 Post subject: Re: CompoundKey/Mapping problem
PostPosted: Wed Mar 03, 2010 11:19 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
morsor wrote:
ItilStatus does not have its own table, but the possible values are found in a table with 5 columns:
...
@Entity
public class ItilStatus


Since you map ItilStatus as entity, it does have its own table. And if three columns are static, why write them to the database at all? Think of normalizing your db.

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject: Re: CompoundKey/Mapping problem
PostPosted: Sat Mar 06, 2010 5:18 am 
Newbie

Joined: Wed Mar 03, 2010 5:04 am
Posts: 2
Quote:
Since you map ItilStatus as entity, it does have its own table.


No - sorry - missed an annotation there - it shares a table with other strings typically used in select in forms, i.e. the table contains 6 different ITILStatus, 5 different Priorities, 10 different Locations and so on.

For this reason three columns are static as regards ITILStatus - and the 3 columns are static (but different) when selecting for Priority or Location.

Quote:
And if three columns are static, why write them to the database at all? Think of normalizing your db.


Unfortunately, I may not change the database at all. I would have had a separate table for each of the above mentioned entities.

I think I will try to create separate views of ITILStatus and Priority and Location from their shared table and map the entities to the views instead of the shared table.

Thanks for your help.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.