-->
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.  [ 6 posts ] 
Author Message
 Post subject: Help with map collections
PostPosted: Tue Dec 21, 2004 10:11 am 
Senior
Senior

Joined: Sun Oct 26, 2003 5:05 am
Posts: 139
Hi.

Let's say I have two tables called business and code and a business can have many codes (so code has a business_id).

Codes are simple. They have an id, a number (varchar) and a reference to the business.

The business table is really umimportant other than I want to have a map property on the Business domain object of codes.

I'd like to make a map collection of codes on the business object where the key/index is the number of the code (not the id) but the element would be the code object itself.

The example in the documentation does not have this example as the index and element are columns. Can I do what I described or should I just use a bag or something?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 21, 2004 1:04 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
so you want both a surrogate id and a key/index in your table ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 21, 2004 1:29 pm 
Senior
Senior

Joined: Sun Oct 26, 2003 5:05 am
Posts: 139
I just want to do something like this:

Code:
Code code = business.getCodes().get( "1234" );
System.out.println( code.getId() );
System.out.println( code.getNumber() ); // prints 1234


Basically the index in the map is the "number" property, not the id. And yes, the number would be unique to the business and there can be no duplicates.[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 21, 2004 2:27 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
egervari,
we have problem understanding your need, can you show us the tables scripts?

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 21, 2004 4:08 pm 
Senior
Senior

Joined: Sun Oct 26, 2003 5:05 am
Posts: 139
Okay, sorry for the confusion. As you can see, carrier_code links to business (business_id). I'd like to create a map property on my Business domain object called getCarrierCodes(). I would expect this map to use the "number" field on the carrier_code table. The elements inside the map should be the CarrierCode domain object itself, not a seperate value. I hope that helps.

Code:
CREATE TABLE carrier_code (
    id integer DEFAULT nextval('carrier_code_id_seq'::text) NOT NULL,
   number character varying(4) NOT NULL,
   business_id integer NOT NULL
);

ALTER TABLE carrier_code ADD CONSTRAINT carrier_code_pkey PRIMARY KEY(id);
ALTER TABLE carrier_code ADD FOREIGN KEY (business_id) REFERENCES business(id) ON UPDATE CASCADE;
CREATE SEQUENCE carrier_code_id_seq;

CREATE TABLE business (
    id integer DEFAULT nextval('business_id_seq'::text) NOT NULL,
    address character varying(100) NOT NULL,
    postal_code character varying(15) NOT NULL,
    province character varying(20) NOT NULL,
    country_id integer NOT NULL,
    phone_number character varying(14) NOT NULL,
    fax_number character varying(14) NOT NULL,
    account_state integer DEFAULT 0 NOT NULL,
    name character varying(40) NOT NULL,
    mailbox character varying(35) NOT NULL,
    city character varying(50) NOT NULL,
    "type" character varying(40) NOT NULL,
    administrator_id integer NOT NULL,
    billing_address character varying(100) NOT NULL,
    billing_city character varying(50) NOT NULL,
    billing_province character varying(20) NOT NULL,
    billing_country_id integer NOT NULL,
    billing_postal_code character varying(15) NOT NULL,
    currency character(3) NOT NULL,
    payment_plan_id integer NOT NULL,
    use_email_invoicing boolean NOT NULL,
    verification_date date,
    approval_date date,
    time_zone_id integer NOT NULL,
    distributor character varying(200) NOT NULL,
    CONSTRAINT business_account_state_check CHECK (((account_state >= 0) AND (account_state <= 3)))
);


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 21, 2004 4:38 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
all you need is to declare mapping with a map indexed on your string column.
Seems easy

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


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