[hibernate-issues] [Hibernate-JIRA] Created: (ANN-836) Availability of @CollectionId in Maps

Vlasov Igor (JIRA) noreply at atlassian.com
Tue May 19 08:48:13 EDT 2009


Availability of  @CollectionId  in Maps 
----------------------------------------

                 Key: ANN-836
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/ANN-836
             Project: Hibernate Annotations
          Issue Type: Improvement
    Affects Versions: 3.4.0.GA
            Reporter: Vlasov Igor


Hello, I have table
user(
id number(10)
name varchar(50)
)

and table 

user_right(
id number(10)
name varchar(50)
key varchar(50)
)

then i want to tie together "user" and "user_right" in table:
rl_user_right(
rl_id number(10)
usr_id number(10)
ur_id number(10)
) 

I can do this in such manner

@OneToMany(fetch = FetchType.LAZY)
 @JoinTable(name = "rl_user_right",
 joinColumns = @JoinColumn(name = "usr_id"),
  inverseJoinColumns = @JoinColumn(name = "ur_id"))
  @CollectionId(columns = @Column(name = "rl_id"),
  type = @org.hibernate.annotations.Type(type = "long"), generator = "identity")
  @org.hibernate.annotations.Fetch(org.hibernate.annotations.FetchMode.SUBSELECT)
  private List<UserRight> rights;

BUT i want to have property of Map type :   private Map<String,UserRight> rights; with "key" value =user_right.key
I try to do :

  @OneToMany(fetch = FetchType.LAZY)
  @JoinTable(name = "rl_user_right",
  joinColumns = @JoinColumn(name = "usr_id"),
  inverseJoinColumns = @JoinColumn(name = "ur_id"))
  @javax.persistence.MapKey(name="ur_key")
  @CollectionId(columns = @Column(name = "rl_id"),
  type = @org.hibernate.annotations.Type(type = "long"), generator = "identity")
  @org.hibernate.annotations.Fetch(org.hibernate.annotations.FetchMode.SUBSELECT)
  private Map<String,UserRight> rights;


Then i catch an exception Map do not support @CollectionId: com.entity.User.rights;

org.hibernate.cfg.annotations.CollectionBinder.getCollectionBinder
.....

if ( java.util.Map.class.equals( returnedClass ) ) {
				if ( property.isAnnotationPresent( CollectionId.class ) ) {
					throw new AnnotationException( "Map do not support @CollectionId: "
							+ StringHelper.qualify( entityName, property.getName() ) );
				}
				return new MapBinder();
			}

How can I achieve my desire with another way?
May be allow @CollectionId  in Maps?


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list