• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

newbie needs help

 
Chris Spierings
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm struggling with the following

Here are my classes (getter and setters omitted to save space)
public class SecurityMeta {

private long taskId = 0;
private ArrayList roles = new ArrayList();
private ArrayList jobs = new ArrayList();

public class RoleMeta {
private long roleId = 0;
private String roleDescription ="";

the roles list will consist of RoleMeta objects

public class JobMeta {
private long jobId = 0;
private String jobDescription ="";

the jobs list will consist of JobMeta objects

The tables look like this:

TJR
meta_task_id
job_id
role_id

Job
job_id
job_desc

Role
role_id
role_desc

what I'm trying to do is configure an hbm file which will permit me to get a SecurityMeta object which is populated with lists of roles and jobs.

I've created simple hbm files to deal with tables individually and classes to read the tables but I'm struggling to do something like I've outlined above giving me an object which draws from multiple tables.

I've spent a fair amount of time looking at the hibernate doc and playing around with the code trying to make something work but I'm struggling with this. Any help is appreciated.

Thanks,

Chris
 
Todd Farmer
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Perhaps posting the hbm.xml files you created already for the individual tables would help. From your post, it sounds as if you are just having difficulty defining the relationships within the configuration files.

It also looks (from the class properties) that you don't have keys that might help you make the relationship between the Task and the associated Roles/Jobs. It might be hard to define relationships without that information.

My guess is that you want to have many Tasks, each of which may be associated with one or more Roles. And each Role may be associated with one or more Tasks. That would be a many-to-many relationship. You may need an intermediate database table to link the two.

Todd Farmer
 
Chris Spierings
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here are the associated HBM files

<hibernate-mapping package="com.amfam.isagent.agtpipeln.containers.meta">
<class name="SecurityMeta" table="TASK_JOB_ROLE"
schema = "agentpipe" lazy="false">

<id name="taskId" type="java.lang.Long" column="META_TASK_ID">
<generator class="native" />
</id>

<property name="jobId" column="JOB_ID" not-null="false" type="java.lang.Long" />
<property name="roleId" column="ROLE_ID" not-null="false" type="java.lang.Long" />

<bag name="roles" table="ROLE">
<key column="ROLE_ID"></key>
<one-to-many class="com.amfam.isagent.agtpipeln.containers.meta.RoleMeta" />
</bag>

<bag name="jobs" table="JOB">
<key column="JOB_ID"></key>
<one-to-many class="com.amfam.isagent.agtpipeln.containers.meta.JobMeta"/>
</bag>




</class>

</hibernate-mapping>


The table task_job_role has 3 columns:

meta_task_id
job_id (fk)
role_id(fk)

Job table

Job_Id (pk)
Job_Desc

Role Table

Role_Id (fk)
Role_Desc


Role Meta Class

public class RoleMeta {
private long roleId = 0;
private String roleDescription ="";

Job Meta

public class JobMeta {
private long jobId = 0;
private String jobDescription ="";


Again getters and setters omitted

Thanks,

Chris
 
Todd Farmer
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's what I notice:

Your SecurityMeta class (as provided) don't have getter and setters for the "jobs" and "roles" Lists that Hibernate will attempt to create as a result of the associations you have defined in the mapping document. Make sure you have getJobs() and getRoles() methods defined (each of which should return a java.util.List), as well as setJobs(java.util.List) and setRoles(java.util.List).

The RoleMeta and JobMeta classes will need hibernate configuration documents themselves, which may exist and just were not provided. If they don't exist, though, that would cause problems.

When you say it doesn't work, can you provide the error you are receiving? The stack trace from problems Hibernate experiences while parsing the mapping documents is invaluable.

Todd Farmer
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic