-->
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: Problems mapping enum
PostPosted: Sat Jan 16, 2010 11:20 am 
Newbie

Joined: Sat Jan 16, 2010 11:03 am
Posts: 2
Hi,
I'm trying to map enums and I have to use join tables. Note: I altered names for anonymity
Below is my mapping
for entity:
Code:
   @ManyToMany (targetEntity=com.somecompany.SomeEnum.class)
   @JoinTable(
      name = "entity_enum",
      joinColumns = { @JoinColumn(name = "entity_id")},
      inverseJoinColumns = { @JoinColumn(name = "enum_id") }
      )
   private Set<SomeEnum> enums = new HashSet<SomeEnum>();

for enum:
Code:
   @Id
   @Column(name = "id", unique = true, nullable = false, insertable = false, updatable = false)
   private  int enumId;
   
   @Column(name = "name", unique = true, nullable = false, insertable = false, updatable = false)
   private  String enumName;


Above code works and runs selects correctly. However throws an exception
Code:
org.springframework.orm.hibernate3.HibernateSystemException: No default constructor for entity: com.somecompany.SomeEnum; nested exception is org.hibernate.InstantiationException: No default constructor for entity: com.somecompany.SomeEnum
   at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:676)
   at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:95)
   at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:212)
   at org.springframework.orm.jpa.JpaAccessor.translateIfNecessary(JpaAccessor.java:152)
   at org.springframework.orm.jpa.JpaTemplate.execute(JpaTemplate.java:189)
   at org.springframework.orm.jpa.JpaTemplate.merge(JpaTemplate.java:276)...............
Caused by: org.hibernate.InstantiationException: No default constructor for entity: com.somecompany.SomeEnum


My enum is derived from a custom base enum. Is my approach correct here? and what are my options to get this working?
Thank you very much in advance.


Top
 Profile  
 
 Post subject: Re: Problems mapping enum
PostPosted: Sun Jan 17, 2010 2:10 am 
Newbie

Joined: Sat Jan 16, 2010 11:03 am
Posts: 2
Answering my own question, above approach is completely nonsense, here is the solution, names change for anonimity.
Code:
   @Enumerated(EnumType.ORDINAL)
   @CollectionOfElements
   @JoinTable(name = "entity_enum_jointable", joinColumns = { @JoinColumn(name = "entity_id") })
   @Column(name = "enum_id")
   private Set<EnumType> entityEnumTypes = new HashSet<EnumType>();


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.