-->
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.  [ 1 post ] 
Author Message
 Post subject: Using persistent Typesafe Enum in many-to-many rel
PostPosted: Mon Oct 11, 2004 1:49 pm 
Newbie

Joined: Mon Oct 11, 2004 1:30 pm
Posts: 15
Location: New York, NY
Details below.

I'm trying to use a persistent enum (cf: http://hibernate.org/203.html) as part of a many-to-many relation.

Please review my configuration mapping below. My assumption (correct me if I'm wrong) is that if i declare a class-entry for a PersistentEnum, then there will be a round-trip to the database to query it. I'd like to avoid that.

The scenario I have outlined below is attempting to create a user-group relationship where a user can be in mulitple groups and vice-versa.

Can someone provide an example of how to accomplish this?

Is my assumption mistaken? If it isn't, then is there a way to configure a Persistent Typesafe Enum mapping class that is read only once from the database?

Thanks in advance
Ed


Hibernate 2.1.6

Name and version of the database you are using:
PostgreSQL 7.4.5
java.version 1.4.2_05

Mapping documents:
(Relevant mappings):
<class name="winetrust.domain.User" table="wt_user">
<id name="id" type="int">
<generator class="native"/>
</id>
<version name="version"/>
<property name="username"
column="username"
not-null="true"
type="string"
unique="true"/>
<property name="password"
column="password"
not-null="true" type="string"/>
<set name="groups"
lazy="false"
cascade="all-delete-orphan">
<key column="user_id"/>
<one-to-many class="winetrust.domain.UserGroupMap"/>
</set>
</class>

<class name="winetrust.domain.UserGroupMap">
<composite-id>
<key-many-to-one name="user"
column="user_id"
class="winetrust.domain.User"/>
<key-many-to-one name="group"
column="group_id"
class="winetrust.domain.vo.UserGroup"/>
</composite-id>
</class>

Code between sessionFactory.openSession() and session.close():
*Never gets that far!

Full stack trace of any exception that occurs:
Exception in constructor: testFindByPk (org.springframework.beans.factory.BeanCreationException: E
rror creating bean with name &apos;wtSessionFactory&apos; defined in (no description): Initialization of bean failed; ne
sted exception is net.sf.hibernate.MappingException: An association from the table UserGroupMap refers to an unmapped cl
ass: winetrust.domain.vo.UserGroup
net.sf.hibernate.MappingException: An association from the table UserGroupMap refers to an unmapped class: winetrust.dom
ain.vo.UserGroup
at net.sf.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:682)
at net.sf.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:666)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:784)
at org.springframework.orm.hibernate.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:467)
at org.springframework.orm.hibernate.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:405
)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowi
reCapableBeanFactory.java:991)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapab
leBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapab
leBeanFactory.java:208)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:204)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:136)
at winetrust.util.Locator.locateSessionFactory(Locator.java:38)
at winetrust.DefaultTestCase.this(DefaultTestCase.java:26)
at winetrust.DefaultTestCase.&lt;init&gt;(DefaultTestCase.java:30)
at winetrust.service.UserServiceTest.&lt;init&gt;(UserServiceTest.java:29)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
at junit.framework.TestSuite.createTest(TestSuite.java:131)
at junit.framework.TestSuite.addTestMethod(TestSuite.java:114)
at junit.framework.TestSuite.&lt;init&gt;(TestSuite.java:75)
at winetrust.service.UserServiceTest.suite(UserServiceTest.java:174)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.&lt;init&gt;(JUnitTestRunner.java:257)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.&lt;init&gt;(JUnitTestRunner.java:219)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeInVM(JUnitTask.java:822)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:556)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:532)
at org.apache.tools.ant.Task.perform(Task.java:341)
at org.apache.tools.ant.Target.execute(Target.java:309)
at org.apache.tools.ant.Target.performTasks(Target.java:336)
at org.apache.tools.ant.Project.executeTarget(Project.java:1339)
at org.apache.tools.ant.Project.executeTargets(Project.java:1255)
at org.apache.tools.ant.Main.runBuild(Main.java:609)
at org.apache.tools.ant.Main.start(Main.java:196)
at org.apache.tools.ant.Main.main(Main.java:235)

The generated SQL (show_sql=true):
* Never gets that far


Debug level Hibernate log excerpt:
* See above


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.