-->
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.  [ 2 posts ] 
Author Message
 Post subject: many-to-many between object and enum
PostPosted: Sun May 01, 2011 4:06 pm 
Newbie

Joined: Sun May 01, 2011 3:45 pm
Posts: 1
I wonder if it is possible to create a many-to-many relationship between an object type and an enum type. There seems to be a more general obstruction with retrieving the list of enum values bound to object, because we cannot have a public constructor in enum type

---

My Hibernate version is 3.6.3.

When I access the roles enum set in user object type I get the following error:

Exception in thread "main" org.hibernate.InstantiationException: No default constructor for entity: foo.MyRole
at org.hibernate.tuple.PojoInstantiator.instantiate(PojoInstantiator.java:107)
at org.hibernate.tuple.PojoInstantiator.instantiate(PojoInstantiator.java:123)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.instantiate(AbstractEntityTuplizer.java:603)
at org.hibernate.persister.entity.AbstractEntityPersister.instantiate(AbstractEntityPersister.java:3911)
at org.hibernate.impl.SessionImpl.instantiate(SessionImpl.java:1422)
at org.hibernate.impl.SessionImpl.instantiate(SessionImpl.java:1411)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1446)
at org.hibernate.loader.Loader.getRow(Loader.java:1355)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:611)
at org.hibernate.loader.Loader.doQuery(Loader.java:829)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
at org.hibernate.loader.Loader.loadCollection(Loader.java:2166)
at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:62)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:627)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:83)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1863)
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:369)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:111)

The object is MyUser and it has a list of MyRole's of enum type.

@Entity
public enum MyRole {
@Enumerated(EnumType.ORDINAL)
USER
,
@Enumerated(EnumType.ORDINAL)
ADMIN;

@Id
public int getRoleId() {
return ordinal();
}

public void setRoleId(int roleId) {
}

}



@Entity
public class MyUser {

private long userId;

@OneToMany(cascade=CascadeType.ALL)
private Set<MyRole> roles = new HashSet<MyRole>();

...

}

I define the many-to-many relationship in the User mapping file:
<set name="roles" table="MYUSER_MYROLE" cascade="all">
<key column="USERID" />
<many-to-many column="ROLEID" class="foo.MyRole" />
</set>


Top
 Profile  
 
 Post subject: Re: many-to-many between object and enum
PostPosted: Tue May 03, 2011 12:48 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
viewtopic.php?f=1&t=924655&start=0
check it.

_________________
Dharmendra Pandey


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