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.  [ 2 posts ] 
Author Message
 Post subject: Problem: Inheritance of entities and adding business code
PostPosted: Thu Sep 10, 2009 9:22 am 
Newbie

Joined: Thu Sep 03, 2009 3:10 am
Posts: 5
I'm trying to use a construction which appears not possible. My creation looks like this (well its a bit simplified):

myProcess.java
Code:
@Entity
@Table(name = "myprocess")
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorFormula("CONCAT(type, '-',action)")

public class myProcess {

   @Id
   @GeneratedValue(strategy = GenerationType.TABLE)
   @Column(name = "id", nullable = false)
   private Integer id;
   
   @Enumerated(EnumType.STRING)
   @Column(name = "type", nullable = false)
   private ProcessTypeEnum type;

   @Column(name = "action", nullable = false)
   private String action;
   
   @Column(name = "status", nullable = false)
   private String status;

   .... <even more stuff and getter/setter> ....
}


contactProcess.java (Extends from myProcess)
Code:
@Entity
@Table(name = "process_contact")
public abstract class ContactProcess extends myProcess {
   @Column(name = "name")
   private String name;

   @Column(name = "city")
   private String city;

   .... <even more stuff and getter/setter> ....
}


createContactProcess.java(Extends from ContactProcess)
Code:
public class CreateContactProcess extends ContactProcess {
   ...Business code...
   public void SaveMe()
   {
      getEntityManager().persist(this);
   }
}


The error i'm getting is:
Quote:
javax.ejb.EJBException: java.lang.IllegalArgumentException: Unknown entity: CreateContactProcess


The createcontactprocess only contains the business logic voor the create. There will also be a delete and update etc. I'm using the extends to prevent having to create the same entities over and over again. And I want to seperate the businesslogic code for a create and delete because its a lot of code.

Side note: In this example i'm not trying to persist the contact itself (like the name suggest) but the data in the createcontactprocess. Because the process can run for a long time and i want to save the data in case something happens with the application server.

Putting the persist function in myprocess doenst change a thing because its being extended down to createContactProcess.

The error doesn't surprise me, but how can I avoid/fix it ?

Update:
When I add @Entity to createContactProcess.java the code works as expected... The Process table and ContactProcess table are filled with the right data. But hibernate generates the table CreateContactProcess with only an Id column. This id column is linked to the Id columns of the other tables. This CreateContactProcess table is useless and shouldn't be created.
So another solution for me would be to prevent hibernate to create the CreateContractProcess table and prevent hibernate to set the Id column of the CreateContactProcess. Is this possible? Does hibernate contains an option to fully auto generate tables from the enities except for one entity (CreateContactProcess)?


Top
 Profile  
 
 Post subject: Re: Problem: Inheritance of entities and adding business code
PostPosted: Mon Sep 14, 2009 10:01 am 
Newbie

Joined: Thu Sep 03, 2009 3:10 am
Posts: 5
*bump*


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