-->
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.  [ 4 posts ] 
Author Message
 Post subject: Defining column names for a Map of core types
PostPosted: Thu Aug 09, 2007 10:44 am 
Newbie

Joined: Thu Aug 09, 2007 7:16 am
Posts: 2
I am trying to override the default-generated column names for a (non-entity) collection of Map<String, String>

An example would the definition of 'myMap' in:

@Entity
public class MyClass {

private Long id;
private Map<String, String> myMap = new HashMap<String, String>();

@Id @GeneratedValue
public Long getId() {
return id;
}

@CollectionOfElements()
public Map<String, String> getMyMap() {
return myMap;
}
}

This results in the schema definition:

create table my_class_my_map
(my_class bigint not null, element varchar(255), mapkey varchar(255), primary key (my_class, mapkey)) type=InnoDB;

However, I would like the auto-generated column names "my_class" and "element" to be user defined.

I reaslise that the column "mapkey" can be defined using:
@org.hibernate.annotations.MapKey(columns = { @Column(name = "my_column_name_here") })

And I *suspect* that what I want to achieve can be accomplished using the annotation:
@AttributeOverride
but nothing works that I have tried so far.

Is there a Hibernate guru out there that can help me?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 10, 2007 8:19 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
just use @Column to override element
and @JoinColumn to override the pk / fk

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 10, 2007 9:31 am 
Newbie

Joined: Thu Aug 09, 2007 7:16 am
Posts: 2
Thank you for your help, emmanuel, I am half way there!

Code:
@Column(name = "my_el_col_name")

overrode the default name of 'element' in the 'Map' table.

However, I did not have any luck with:
Code:
@JoinColumn(name = "my_fk_col_name")

It seemed to have no effect.
I was wondering if I needed to specify attributes other than just 'name' in the @JoinColumn?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 10, 2007 10:57 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Ah sorry, this is indeed
@JoinTable(joinColumns=@JoinColumn(...)

_________________
Emmanuel


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