-->
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: How do I setup annotatio for JOINED inheritance with comp PK
PostPosted: Wed Mar 28, 2012 6:53 am 
Newbie

Joined: Wed Mar 28, 2012 6:19 am
Posts: 1
I am new to hibernate and having a tough time trying to wrap my head around setting up Joined inheritance with composite Primary Key. With my current setup, I get a:

JDBCException: could not insert: LandHolidayPackage

I am essentially looking for two things:

    Are the inheritance annotations in place ?
    Is the composite PK (IDHOLIDAYPACKAGEVARIANT, IDHOLIDAYPACKAGE) setup properly ?

DB Design:
Image

text description

Here are my classes and the annotations involved:

Code:
@Entity
@Table(name = "HOLIDAYPACKAGE")
public final class HolidayPackage {
   private Integer idPackage;
   private String name;
   
   private Set<HolidayPackageVariant> holidayPackageVariants = new HashSet<HolidayPackageVariant>(0);
   
   @Id
   @GeneratedValue(strategy = GenerationType.IDENTITY)
   @Column(name = "IDHOLIDAYPACKAGE", nullable = false)
   public Integer getIdPackage() {
      return idPackage;
   }
   
   @OneToMany(fetch=FetchType.LAZY, cascade={CascadeType.ALL}, mappedBy = "holidayPackage")
   public Set<HolidayPackageVariant> getHolidayPackageVariants() {
      return holidayPackageVariants;
   }
   
   // ommitted other part of the code
   }
   
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
@Table(name="HOLIDAYPACKAGEVARIANT")
public abstract class HolidayPackageVariant {
   private Integer idHolidayPackageVariant;
   private HolidayPackage holidayPackage;
   private String typeHolidayPackage;
   
   @Id
   @GeneratedValue(strategy=GenerationType.IDENTITY)
   @Column(name="IDHOLIDAYPACKAGEVARIANT", nullable=false)
   public Integer getIdHolidayPackageVariant() {
      return idHolidayPackageVariant;
   }

   @ManyToOne(fetch=FetchType.LAZY, cascade={CascadeType.ALL})
   @JoinColumn(name="IDHOLIDAYPACKAGE", nullable=false)
   public HolidayPackage getHolidayPackage() {
      return holidayPackage;
   }

   @Column(name="TYPEHOLIDAYPACKAGE", nullable=true)
   public String getTypeHolidayPackage() {
      return typeHolidayPackage;
   }
   
   // ommitted setters, equals hashCode
   }
   
@Entity
@Table(name="LANDHOLIDAYPACKAGEVARIANT")
public final class LandHolidayPackageVariant extends HolidayPackageVariant{
   private static final String LAND = "LAND";
   
   protected LandHolidayPackageVariant() {}

   public LandHolidayPackageVariant(HolidayPackage holidayPackage) {
      super(holidayPackage, LAND);
   }
   }
   
@Entity
@Table(name="FLIGHTHOLIDAYPACKAGEVARIANT")
public final class FlightHolidayPackageVariant extends HolidayPackageVariant{
   private static final String FLIGHT = "FLIGHT";
   private Destination originCity;
   
   protected FlightHolidayPackageVariant(){}

   public FlightHolidayPackageVariant(HolidayPackage holidayPackage,
         Destination originCity) {
      super(holidayPackage, FLIGHT);
      setOriginCity(originCity);
   }

   @ManyToOne(fetch=FetchType.LAZY, cascade={CascadeType.ALL})
   @JoinColumn(name="IDDESTINATION", nullable=false)
   public Destination getOriginCity() {
      return originCity;
   }
   
   // ommited other setters etc functions
   }


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.