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.  [ 1 post ] 
Author Message
 Post subject: @OneToMany - list content not fetched
PostPosted: Wed Aug 26, 2009 5:24 am 
Newbie

Joined: Wed Aug 27, 2008 8:33 am
Posts: 3
Location: GdaƄsk [Poland]
Hello,

I have a problem with @OneToMany relation when it points one of entity subclass.

I have the basinc Application entity which is connected with all objects and I want this entity to have a list of ManagedCompany entityes (not its superclass Company). Is this possible? Everything is fine when I choose List<Company>, but List<ManagedCompany> always is empty despite that entities of this type exists in database.


Source of Application entity containing ManagedCompany relation.

Code:
package org.pg.alex.fakturant.dal.model;

import java.util.Date;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import org.pg.alex.fakturant.common.dto.ApplicationDTO;
import org.pg.alex.fakturant.common.dto.CompanyDTO;
import org.pg.alex.fakturant.common.dto.DateDTO;
import org.pg.alex.fakturant.common.enums.LicenseType;
import org.pg.alex.fakturant.dal.dao.util.DTOListUtil;
import org.pg.alex.fakturant.dal.intf.DTOTransformer;

/**
* Represents an Application entity.<br/>
* Each system entity must be associated with particular application. Application can contain references to many companies depending on the license.<br/>
* @author alech
*/
@Entity
@Table(name="application")
@SequenceGenerator(name="application_sequence", sequenceName="application_seq")
public class Application implements DTOTransformer<ApplicationDTO> {

   @Id
   @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="application_sequence")
   private long id;
   @Column(unique=true, nullable=false)
   private String appKey;
   @Column(unique=true, nullable=false)
   private String appSerialKey;
   @Enumerated(EnumType.ORDINAL)
   private LicenseType license;
   private Date subscriptionStartDate;
   private Date subscriptionEndDate;
   @OneToMany
   private List<ManagedCompany> managedCompanies;
   
   [ ... ]
}



And here comes the Company base entity and its subclass - ManagedCompany.

Code:
/**
*
*/
package org.pg.alex.fakturant.dal.model;

import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.Lob;
import javax.persistence.SequenceGenerator;
import org.pg.alex.fakturant.common.dto.CompanyDTO;
import org.pg.alex.fakturant.common.types.Address;
import org.pg.alex.fakturant.dal.intf.DTOTransformer;

/**
* @author aleX
*
*/
@Entity
@Inheritance
@DiscriminatorColumn(name="type", discriminatorType=DiscriminatorType.INTEGER)
@DiscriminatorValue("0")
@SequenceGenerator(name="company_sequence", sequenceName="company_seq")
public abstract class Company extends AbstractEntity implements DTOTransformer<CompanyDTO> {
   
   @Id
   @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="company_sequence")
   protected long id;
   @Embedded
   protected Address address;
   protected String nip;
   protected String phoneNumber;
   protected String website;
   protected String email;
   protected String additionalInfo;
   @Lob
   protected byte[] logoImage;
   
   public Company() {
      // TODO Auto-generated constructor stub
   }

   [ .. ]


}



Code:
/**
*
*/
package org.pg.alex.fakturant.dal.model;

import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;

/**
* @author alex
*
*/
@Entity
@DiscriminatorValue("2")
public class ManagedCompany extends Company {

}




Probably its simple but I got a little bit confused, just need another developer to take look at this:) Any posts apreciated!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.