-->
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: Problem with Inheritance and Associations
PostPosted: Mon May 28, 2007 4:47 am 
Newbie

Joined: Mon May 28, 2007 4:38 am
Posts: 2
Hi everybody, I have a problem with Polymorphic Associations. First of all my entities:

@Entity
@Table(name = "customer")
@Inheritance(strategy = InheritanceType.JOINED)
@IdClass(CustomerPk.class)
public class Customer {
@OneToMany(targetEntity=Order.class, mappedBy="customer"
public List<Order> getOrders() {
return orders;
}

public void setOrders(List<Order> orders) {
this.orders = orders;
}
}

(PK is lastname and firstname)

@Entity
@Table(name = "privatecustomer")
@PrimaryKeyJoinColumns( { @PrimaryKeyJoinColumn(name = "firstname", referencedColumnName="firstname"),
@PrimaryKeyJoinColumn(name = "lastname", referencedColumnName="lastname") })
public class PrivateCustomer extends Customer {
... additional properties
}

@Entity
@Table(name = "businesscustomer")
@PrimaryKeyJoinColumns( { @PrimaryKeyJoinColumn(name = "firstname", referencedColumnName="firstname"),
@PrimaryKeyJoinColumn(name = "lastname", referencedColumnName="lastname") })
public class BusinessCustomer extends Customer{
... additional properties
}


@Entity
@Table(name = "ord")
public class Order {

@ManyToOne(targetEntity = JPACustomer.class)
@JoinColumns({
@JoinColumn(name="customer_firstname"),
@JoinColumn(name="customer_lastname")
})
public Customer getCustomer() {
return customer;
}

public void setCustomer(Customer customer) {
this.customer = customer;
}
}


Now, my problem is that the association on the customer side is not fetched. No matter which fetchType (Eager, Lazy) i use, hibernate generates no query to fetch the associated orders. No exception, no errors, nothing. Customer.getOrders() simply return null. Have I missed something in my mapping?

thanks for any help
martin


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 29, 2007 2:59 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Maybe you're mixing field and getter annotations?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 01, 2007 6:19 am 
Newbie

Joined: Mon May 28, 2007 4:38 am
Posts: 2
I don't think so, I have mapped the relationship exactly like in the Hibernate Annotations Document Page 23. And it works if i remove the inheritance and try it only with a customer class without subclasses. But as soon as i add inheritance the relationship doesn't get fetched anymore.
Any more advice?


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.