-->
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: Not inserting into many-to-many table
PostPosted: Wed Mar 30, 2005 11:42 pm 
Newbie

Joined: Tue Mar 22, 2005 10:31 pm
Posts: 8
I will try to keep this short, because I know time is important, but I am pretty stuck. I have recently implemented Hibernate into a project I am working on. I wrote my hbm files by hand and used hbm2java to create my classes. This was before I found out that hbm2java is not really supported anymore (at least not maintained). Both books I have been using
"Hibernate A Developer's Handbook" and
"Hibernate A J2EE Developer's Guide" discussing starting with the hbm files. Well never the less. My problem is that I have one table called Jobs and another table called Skills. Now any job can have a multitude of skills. So I have a many-to-many relationship. Well what's happening is that the job is getting inserted into the hsqldb, but the join table is not getting updated. Below is my hbm.xml files:

------- Job.hbm.xml ---------
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping>

<class name="com.echostorm.resumes.evaluator.hibernate.Job" table="JOB">

<meta attribute="class-description">
Represents a Job with which multiple skills can be assigned
@author JVince Cordaro (with help from Hibernate)
</meta>

<id name="id" type="string" column="JOB_ID">
<meta attribute="finder-method">findByID</meta>
<generator class="uuid.hex" />
</id>
<version column="revision" name="revision" />

<property name="title" type="string"
column="TITLE" length="100">
<meta attribute="finder-method">findByTitle</meta>
</property>

<property name="department" type="string"
column="DEPARTMENT" length="100">
<meta attribute="finder-method">findByDepartment</meta>
</property>

<property name="description" type="string"
column="DESCRIPTION" length="500" />

<property name="date" type="string"
column="date" length="100" >
<meta attribute="finder-method">findByDate</meta>
</property>

<property name="interviewerID" type="string"
column="interviewerID" length="50" >
<meta attribute="finder-method">findByInterviewerID</meta>
</property>

<property name="clearance" type="string"
column="clearance" length="100" >
<meta attribute="finder-method">findByClearance</meta>
</property>

<property name="location" type="string"
column="location" length="100">
<meta attribute="finder-method">findByLocation</meta>
</property>
<property name="statusID" type="string"
column="statusID" length="100">
<meta attribute="finder-method">findByStatusID</meta>
</property>

<set name="skills" table="JOB_SKILLS" inverse="true">
<meta attribute="field-description">Skills for Job</meta>
<key column="JOB_ID"/>
<many-to-many class="com.echostorm.resumes.evaluator.hibernate.Skill" column="SKILL_ID"/>
</set>
</class>
</hibernate-mapping>

-------------------------------------------------------------------

----- Skill.hbm.xml ---------------------------------------------

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping>

<class name="com.echostorm.resumes.evaluator.hibernate.Skill" table="skill">

<id name="id" type="string" column="SKILL_ID">
<meta attribute="finder-method">findByID</meta>
<generator class="uuid.hex" />
</id>

<version column="revision" name="revision" />

<property name="name" type="string"
column="name" length="100" >
<meta attribute="finder-method">findByName</meta>
</property>

<property name="description" type="string"
column="description" length="500" />

<property name="department" type="string"
column="department" length="100" >
<meta attribute="finder-method">findByDepartment</meta>
</property>

<set name="jobs" table="JOB_SKILLS" inverse="true">
<meta attribute="field-description">Jobs that use this skill</meta>
<key column="SKILL_ID"/>
<many-to-many class="com.echostorm.resumes.evaluator.hibernate.Job" column="JOB_ID"/>
</set>

</class>
</hibernate-mapping>

----------------------------------------------------------------------------------

As you can see I have my set tag setup. At least that's how the books have been showing it. It did build the db, with a skill table, job table, and JOB_SKILLS table. However the JOB_SKILLS table never get's updated like I mentioned before.

Here is my code for inputing a new job:


----


try{

Transaction trans = hibernateSession.beginTransaction();
myJob.setTitle(ar.getParameter("title"));
myJob.setDescription(ar.getParameter("description"));
myJob.setDepartment(ar.getParameter("department"));
myJob.setClearance(ar.getParameter("clearance"));
myJob.setSkills(new HashSet());
long i = System.currentTimeMillis();
String t = Long.toString(i);
myJob.setDate(t);
myJob.setStatusID(StatusHandler.getIDByName(hibernateSession,"open"));

// Get skill id's from list box in portal page
String[] skills = ar.getParameterValues("skills");


for(int k=0; k<skills.length; k++)
{
Skill tempSkill = SkillHandler.getSkillByID(hibernateSession,skills[k]);
logger.debug("Setting skill for job : " +tempSkill.getName());
myJob.getSkills().add(tempSkill);

}


hibernateSession.save(myJob);
trans.commit();
}


----------------------

I have put in logging comments to make sure that the skills are getting added. And they seem to be because the logger shows skills being added. However when the save gets called the Job gets added but the JOB_SKILLS table never get's touched. I have show sql turned on for hibernate and I do not see any insert into JOB_SKILLS after I see the insert into JOB. I have also used the HSQL Database Manager to see if the table is still empty and it is.
The SkillHandler is just a class the extends the SkillFinder that hibernate made. My SkillHandler has methods dealing with skills of course. The getSkillByID takes in the session along with the id string to return a skilll.

Does anyone have any idea what's wrong, or can someone give me or point me to an example?

Thanks in advance,


Vince Cordaro


Top
 Profile  
 
 Post subject: took off set on skills
PostPosted: Thu Mar 31, 2005 12:19 am 
Newbie

Joined: Tue Mar 22, 2005 10:31 pm
Posts: 8
I took off the set tag in the skills.hbml.xml because apparently I do not need it. I only need the set tag job.hbm.xml. When I ran it. The proper tables where created, but still JOB_SKILLS was not updated.


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.