-->
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: Attribute mapping for custom SQL output
PostPosted: Tue Nov 02, 2010 7:44 pm 
Newbie

Joined: Tue Nov 02, 2010 7:01 pm
Posts: 2
I am working on an existing domain model and using Hibernate Annotations. I have problem mapping an entity and need some help/inputs/ideas/suggestions.

Here is the scenario, I have 4 tables:
1) Oraganization (Org_id(primary key), Org_num, Org_name, etc...)
2) Office (Off_id (primary key), Org_id, Off_name, etc...)
3) Service (Svc_id (primary key), Svc_desc)
4) Office_Service (Off_id, Svc_id)

The issue is with mapping the SERVICES attribute in Organization entity. In my Organization entity I want list of service and my services are not directly linked to Organization. I have to write a custom SQL query to get the list, but I am not sure how to map. My Organization entity is some thing like this

@Entity
@Table(name = "Oraganizations")
public class EmploymentNetwork implements Serializable {

@Id
@Column(name = "Org_id")
private String orgId;

@Column(name = "Org_num")
private String orgNumber;

@OneToMany
//????
private List<Service> services;
}

I can't use JOINS, NAMEDNATIVEQUERY or....

Hope there is a way to map the scenario, looking forward for suggestions and ideas.


Top
 Profile  
 
 Post subject: Re: Attribute mapping for custom SQL output
PostPosted: Wed Nov 03, 2010 5:14 pm 
Newbie

Joined: Tue Nov 02, 2010 7:01 pm
Posts: 2
I tried the following mapping to address the above issue

@Entity
@Table(name = "Oraganizations")
@NamedNativeQuery(name = "Services", query = "SELECT.............................", resultClass = Service.class)
public class EmploymentNetwork implements Serializable {

@Id
@Column(name = "Org_id")
private String orgId;

@Column(name = "Org_num")
private String orgNumber;

@OneToMany
@Loader(namedQuery = "Services")
@JoinColumn(name = "Org_id")

private List<Service> services;
}

When I tried this mapping I am getting an exception

Exception in thread "main" java.lang.NullPointerException
at org.hibernate.collection.PersistentBag.size(PersistentBag.java:248)


Does anyone know what the issue?


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.