-->
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-one relathionship don't map
PostPosted: Thu Jun 03, 2010 5:05 pm 
Newbie

Joined: Mon May 24, 2010 3:25 pm
Posts: 6
I need your help with this mapping driving me crazy...

I've got class Job that has has a type; thus many jobs can have the same type.
My JOBS table holds a FK to POS_TITLE_TYPES_DIR, but in runtime the object that holds the reference to the types is not mapped and gets NULL.

class Job:
public class Job implements Serializable
{
// Properties
public Long id;
public String title;
public PositionTitleType type;

public Job()
{
}

// Getters / Setters
public Long getId() { return id; }
public void setId(Long id) { this.id = id; }
// Title
public String getTitle() { return title;}
public void setTitle(String title) { this.title = title; }
// TitleType
public PositionTitleType getType() { return type; }
public void setType(PositionTitleType type) { this.type = type; }
}

class PositionTitleType
package jobpro;
import java.io.Serializable;
public class PositionTitleType implements Serializable
{
// Properties
public Long id;
public String type;

public PositionTitleType() { }
// Getters / Setters
public Long getId() { return id; }
public void setId(Long id) { this.id = id; }
// Type
public String getType() { return type; }
public void setType(String type) { this.type = type; }
}


Job Mapping
<hibernate-mapping package="jobpro">
<class name="jobpro.Job" table="JOBS">
<id name="id" column="ID">
<generator class="native"/>
</id>
<property name="title" column="TITLE"/>
<many-to-one name="type" class="jobpro.PositionTitleType" column="POS_TITLE_TYPE_ID"/>
<query name="JOBS.findAll"><![CDATA[from Job]]></query>
</class>
</hibernate-mapping>


PositionTitleType Mapping:
<hibernate-mapping package="jobpro">
<class name="jobpro.PositionTitleType" table="POS_TITLE_TYPES_DIR">
<id name="id" column="ID">
<generator class="assigned"/>
</id>
<property name="type" column="TYPE"/>
</class>
</hibernate-mapping>


--> What am I missing here???


Top
 Profile  
 
 Post subject: Re: Many-to-one relathionship don't map
PostPosted: Fri Jun 04, 2010 6:18 am 
Newbie

Joined: Mon May 24, 2010 3:25 pm
Posts: 6
Aha! found my problem.. or at least how to overcome it...
for sake for others - here it is:
My associated object was not loaded from the database at all due to lazy loading, so Ive defined this association as non-lazy:
<many-to-one name="type" class="jobpro.PositionTitleType" column="POS_TITLE_TYPE_ID" lazy="false"/>

Enjoy, Haim


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.