-->
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.  [ 5 posts ] 
Author Message
 Post subject: Persisting a collection of enum using annotations
PostPosted: Wed Mar 12, 2008 9:02 pm 
Newbie

Joined: Tue Apr 24, 2007 6:39 pm
Posts: 7
Hibernate version:
hibernate: 3.2.3.ga
hibernate-annotations: 3.2.1.ga

Mapping documents:
None

I have an entity [User] which has a property [Subspecialty].

Subspecialty is a simple java.lang.Enum

This I can persist without issue.

The problem is that I need a Collection of Subspecialty.

Code:
    @ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
    public Collection<Subspecialty> getSubspecialties() {
        return subspecialties;
    }

    public void setSubspecialties(Collection<Subspecialty> subspecialties) {
        this.subspecialties = subspecialties;
    }


This gives an exception:
...
Caused by: org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: ...model.User.subspecialties[...model.Subspecialty]
...

That is a little perplexing (though not entirely unexpected) given Hibernate is clever enough to persist the Subspecialty without any help in the first case.

Okay so Subspecialty needs to be an Entity? How do you annotate an enum? All combinations I've tried present one error or another. I can change it to a class with some static fields and it all works, but the point is to use an enum.

Before annotations, I used a UserType class to accomplish this persistence, and simply mapped the Subspecialty to the SubspecialtyUserType. But despite my best efforts, I have not been able to get the annotations to work (I know the SubspecialtyUserType will work if mapped properly).

So my question is: how do you persist a collection of enum using annotations?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 14, 2008 11:21 pm 
Newbie

Joined: Sun Mar 19, 2006 9:21 pm
Posts: 3
Hi:

I am having the _exact_ same problem.

Did you ever get an answer to this?

Cheers,
Chris


Top
 Profile  
 
 Post subject: Not so far
PostPosted: Sat Mar 15, 2008 1:30 am 
Newbie

Joined: Tue Apr 24, 2007 6:39 pm
Posts: 7
Nothing yet. I'm forced to use an entity class to represent my enum, java 1.4 style.

It doesn't seem like an unusual use case, in fact quite the contrary, but it's hard to find much about it at all, and none of the many ways I've tried work.

Cheers,

J


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 27, 2008 11:05 am 
Newbie

Joined: Thu Mar 27, 2008 10:50 am
Posts: 13
We use the Hibernate annotation
Code:
@org.hibernate.annotations.CollectionOfElements
when we want to map a collection of an enum.


Top
 Profile  
 
 Post subject: Sweet!
PostPosted: Thu Mar 27, 2008 12:53 pm 
Newbie

Joined: Tue Apr 24, 2007 6:39 pm
Posts: 7
I knew it had to be something simple.


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