-->
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.  [ 6 posts ] 
Author Message
 Post subject: which inheritance strategy is best for this situation
PostPosted: Wed Mar 03, 2010 2:41 am 
Newbie

Joined: Wed Mar 03, 2010 2:31 am
Posts: 3
I have 3 tables which are arranged like this.

Parent has 2 columns ID and Type. Type is a string which determines the child.
Child1 has 3 columns ID, c11 and c12. ID is linked to ID of Parent as a foreign key.
Child2 has 3 columns ID, c21 and c22. ID is linked to ID of Parent as a foreign key.

Thank you.


Top
 Profile  
 
 Post subject: Re: which inheritance strategy is best for this situation
PostPosted: Wed Mar 03, 2010 5:37 am 
Senior
Senior

Joined: Wed Sep 19, 2007 9:31 pm
Posts: 191
Location: Khuntien (Indonesia)
I think you can use table per subclass dan remove 'type' in parent table.


Top
 Profile  
 
 Post subject: Re: which inheritance strategy is best for this situation
PostPosted: Wed Mar 03, 2010 7:33 am 
Newbie

Joined: Wed Mar 03, 2010 2:31 am
Posts: 3
I am using the table per subclass method. However i am running into a problem. It is reading from the database fine but writing to the database fails , be it insertion, deletion or updation. Hibernate does not throw an exception and tells me that the data is written but when i check the database its not there. Any idea why this might be happening ?
I am using Spring Daos for this. I am pasting the Pojos below

Parent Class
Code:
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
@Table(name = "PARENT", schema = "TEST")
public class Parent implements java.io.Serializable {

   // Fields

   private Long parentid;
   private String type;
   
   // Constructors

   /** default constructor */
   public Parent() {
   }

   /** full constructor */
   public Parent(Long id, String type) {
      this.parentid = id;
      this.type = type;
   }

   // Property accessors
   @Id
   @Column(name = "PARENTID", unique = true, nullable = false, precision = 12, scale = 0)
   public Long getParentid() {
      return this.parentid;
   }

   public void setParentid(Long id) {
      this.parentid = id;
   }

   @Column(name = "DTYPE", nullable = true, length = 25)
   public String getType() {
      return this.type;
   }

   public void setType(String type) {
      this.type = type;
   }

}


Child Class Code
Code:

/**
* Child1 entity. @author MyEclipse Persistence Tools
*/
@Entity
@Table(name = "CHILD1", schema = "TEST")
@PrimaryKeyJoinColumn(name="ID", referencedColumnName="PARENTID" )
public class Child1 extends com.sime.test.Parent implements
      java.io.Serializable {

   // Fields

   
   private String c11;
   private String c12;
   private String c13;

   // Constructors

   /** default constructor */
   public Child1() {
   }

   
   /** full constructor */
   public Child1(Long id, String type, String c11, String c12, String c13) {
      //this.id = id;      
      this.c11 = c11;
      this.c12 = c12;
      this.c13 = c13;
      setParentid(id);
      setType(type);
   }

   

   @Column(name = "C11", length = 25)
   public String getC11() {
      return this.c11;
   }

   public void setC11(String c11) {
      this.c11 = c11;
   }

   @Column(name = "C12", length = 25)
   public String getC12() {
      return this.c12;
   }

   public void setC12(String c12) {
      this.c12 = c12;
   }

   @Column(name = "C13", length = 25)
   public String getC13() {
      return this.c13;
   }

   public void setC13(String c13) {
      this.c13 = c13;
   }

}


Top
 Profile  
 
 Post subject: Re: which inheritance strategy is best for this situation
PostPosted: Wed Mar 03, 2010 8:26 am 
Senior
Senior

Joined: Wed Sep 19, 2007 9:31 pm
Posts: 191
Location: Khuntien (Indonesia)
Hi,

I have tested your entity. It works fine.
I suspect your dao is incorrect. Can you post your code how you store the data?


Top
 Profile  
 
 Post subject: Re: which inheritance strategy is best for this situation
PostPosted: Wed Mar 03, 2010 8:30 am 
Senior
Senior

Joined: Wed Sep 19, 2007 9:31 pm
Posts: 191
Location: Khuntien (Indonesia)
Hi,

I have tested your entity. It works fine.
I suspect your dao is incorrect. Can you post your code how you store the data?


Top
 Profile  
 
 Post subject: Re: which inheritance strategy is best for this situation
PostPosted: Wed Mar 03, 2010 9:10 am 
Newbie

Joined: Wed Mar 03, 2010 2:31 am
Posts: 3
I found the error, i had not defined transaction manager in the applicationContext.xml file. Once i did that, it works like a charm. Thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.