-->
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: annotations on multiple extends on class entity
PostPosted: Mon Apr 02, 2012 8:20 pm 
Newbie

Joined: Mon Apr 02, 2012 3:27 pm
Posts: 6
Good Day,

I am trying to make a class extends relationship between several classes, and I have found now luck in examples to do this, this should be rather simple I would think, but don't seem to find the right thing, so here is what I am asking for.

Code:
public abstract class Resource implements Serializable {

   private static final long serialVersionUID = 1L;
   
   @Id
   @Column protected String id;
   
   public Resource(String id){
      this.id = id;
   }


Code:
public abstract class RtTemplate extends Resource implements Comparable<RtTemplate>, Serializable {

   private static final long serialVersionUID = 1L;
   
   @Column(name="iuia", length=150, nullable=false, unique=true)
   protected String iuia;
   
   public RtTemplate(String id, String iuia){
      super(id);
      this.iuia = iuia;
   }


Code:
public class Relation extends RtTemplate implements Serializable {

   private static final long serialVersionUID = 1L;
   
   @Column protected String iuip;
   @Column protected StandardPrediction ta;
   @Column protected StandardPrediction tr;
   
   public Relation(String id, String iuia, String iuip, StandardPrediction ta, StandardPrediction tr){
      super(id, iuia);
      this.iuip = iuip;
      this.iuia = iuia;
      this.tr = tr;
      this.ta = ta;
   }


Code:
@Entity
@Table(name="pton")
public class PtoN extends Relation implements Serializable {

   private static final long serialVersionUID = 1L;
   
   @Column protected String nt;
   @Column protected String n;
   @Column protected String iuic;


   public PtoN(String id, String iuip, String iuia, String iuic, String nt, String n, StandardPrediction ta, StandardPrediction tr){
      super(id, iuia, iuip, ta, tr);
      this.nt = nt;
      this.n = n;
      this.iuic = iuic;
   }


this is the setup, and I have other Pto? classes that do the same think, so I need a little help to map these classes.

and do I need the hashcode and equals in all classes????

and put this all in one table.

thanks in advance,


Top
 Profile  
 
 Post subject: Re: annotations on multiple extends on class entity
PostPosted: Wed Apr 04, 2012 11:45 am 
Newbie

Joined: Mon Apr 02, 2012 3:27 pm
Posts: 6
I assume no one has done any complex programs, since no senior members have committed on this.

maybe I need to look at something other than hibernate.


Top
 Profile  
 
 Post subject: Re: annotations on multiple extends on class entity
PostPosted: Thu Apr 05, 2012 3:16 am 
Senior
Senior

Joined: Tue Oct 28, 2008 10:39 am
Posts: 196
Your assumption is wrong. There are lots of really complex programs using hibernate. You are looking for the right strategy to map your entities to table, so have a look at
@Inheritance(strategy=InheritanceType.JOINED/SINGLE_TABLE/TABLE_PER_CLASS) and @MappedSuperclass

If you need equals/hashCode depends on your application. Have a look at http://docs.jboss.org/hibernate/orm/3.3 ... asses.html (Chapter 4.3)


Top
 Profile  
 
 Post subject: Re: annotations on multiple extends on class entity
PostPosted: Fri Apr 06, 2012 8:35 am 
Newbie

Joined: Mon Apr 02, 2012 3:27 pm
Posts: 6
Well, I have tried the

@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@Table(name="pton")
@DiscriminatorColumn(name="TYPE", discriminatorType=DiscriminatorType.INTEGER)
public class PtoN extends Relation implements Serializable {

and

@Entity
@DiscriminatorValue("1")
public class Relation extends RtTemplate implements Serializable {

and

@Entity
@DiscriminatorValue("1")
public class RtTemplate extends Resource implements Comparable<RtTemplate>, Serializable {

and

@MappedSuperclass
public abstract class Resource implements Serializable {

but then it wants to insert a table called ReTemplate instead of using the pton as designated above.

I wish the Dtype column was not there, but I could careless for an extra column at this point.

thanks.


Top
 Profile  
 
 Post subject: Re: annotations on multiple extends on class entity
PostPosted: Fri Apr 13, 2012 8:51 am 
Newbie

Joined: Mon Apr 02, 2012 3:27 pm
Posts: 6
Solved, by my own experimentations.

this is how it is done.

Code:
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
@Table(name="pton")
public class PtoN extends Relation implements Serializable {

   private static final long serialVersionUID = 1L;
   
   @Column protected String nt;
   @Column protected String n;
   @Column protected String iuic;


Code:
@MappedSuperclass
public class Relation extends RtTemplate implements Serializable {

   private static final long serialVersionUID = 1L;
   
   @Column protected String iuip;
   @Transient protected StandardPrediction ta;
   @Transient protected StandardPrediction tr;


Code:
@MappedSuperclass
public class RtTemplate extends Resource implements Comparable<RtTemplate>, Serializable {

   private static final long serialVersionUID = 1L;
   
   @Column protected String iuia;


and so on, this will allow for multiple Pto? classes to be mapped to the extended classes, beware of date's, that is what I used the @Transient for to deal with that particular varible.

So this works well, as least for what I am trying to accomplish.

Steve


Top
 Profile  
 
 Post subject: Re: annotations on multiple extends on class entity
PostPosted: Tue Apr 17, 2012 3:49 pm 
Newbie

Joined: Mon Apr 02, 2012 3:27 pm
Posts: 6
From what I have learned, through my dealing, I have multiple clases the extend the same classes, so for instance

So what I have done is set all my extended classes as a superclass using the one class as InheritanceType.JOINED, and this is just to make my one
single table from all the classes associated with it, this is what I wanted to accomplish, so to give you a idea, ptop extends relation, extends template,
extends resource. and with that said, my other classes would be pton extends relation, extends template, extends resource and each main class listed in my solution was a single table, which is what I wanted and they all work fine, then setup you dao to presist and it works. I use the Entity on the ptop,pton, pto? for what tables I need to populate.

I hope this gives some insight, and by the way, I did this from trial and error, I did not find any documentation to help as well.

If you need more help, post the top part of the model classes and I as I did above.

Steve


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.