-->
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.  [ 3 posts ] 
Author Message
 Post subject: Programmatic configuration issue with many-to-many?
PostPosted: Tue Sep 11, 2007 2:09 pm 
Newbie

Joined: Tue Oct 25, 2005 2:34 pm
Posts: 12
The way I understand it is because I'm loading Course.class before User.class and Course.class refers to User.class it's saying that User.class doesn't exist yet. It's the chicken or the egg situation. How can I fix this?

Hibernate Version: 3.2.5

Code##################################

SessionFactory factory = new Configuration()
.addClass(Course.class)
.addClass(User.class)
.setProperties(props)
.buildSessionFactory();

Hbm################################
<class name="org.savvylms.api.course.Course" table="SV_COURSES">
<id name="id" column="sv_id">
<generator class="identity"/>
</id>
<property name="name" column="sv_name"/>
<property name="type" column="sv_type"/>

<set name="users" table="SV_COURSE_USER">
<key column="sv_course_id"/>
<many-to-many class="User" column="sv_user_id"/>
</set>

</class>


<class name="org.savvylms.api.user.User" table="SV_USERS">
<id name="id" column="sv_id">
<generator class="identity"/>
</id>
<property name="username" column="sv_username"/>
<property name="password" column="sv_password"/>
<property name="fname" column="sv_fname"/>
<property name="lname" column="sv_lname"/>
<property name="email" column="sv_email"/>

<!--map name="attributes">
<key column="sv_user_id" on-delete="cascade" not-null="true"/>
</map-->

<set name="courses" table="SV_COURSE_USER" inverse="true">
<key column="sv_user_id"/>
<many-to-many class="Course" column="sv_course_id"/>
</set>

</class>

Stack##############################
INFO: Mapping collection: org.savvylms.api.user.User.courses -> SV_COURSE_USER
Exception in thread "main" org.hibernate.MappingException: An association from the table SV_COURSE_USER refers to an unmapped class: User
at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:1252)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1170)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1286)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 11, 2007 8:13 pm 
Newbie

Joined: Tue Oct 25, 2005 2:34 pm
Posts: 12
I just changed to use the hibernate.cfg.xml and it still gives me the same error. So I'm mapping something wrong. But what?


Top
 Profile  
 
 Post subject: Eureka!! I got it.
PostPosted: Tue Sep 11, 2007 9:41 pm 
Newbie

Joined: Tue Oct 25, 2005 2:34 pm
Posts: 12
I simply changed my mappings to full paths. So this:

<many-to-many class="org.savvylms.api.user.User" column="sv_user_id"/>

Simple enough. Is this a good method? Or should I be using something else here?


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