Results 1 to 5 of 5
- 03-24-2010, 11:58 AM #1
Member
- Join Date
- Mar 2010
- Posts
- 11
- Rep Power
- 0
@MappedSuperclass question (javax.persistence) - is it only allowed once?
Hi!
I have made an interesting discovery and was wondering whether I missed out something.
I am using Hibernate for certain entities, and using @MappedSuperClass.
ie. I have a base class (simplified):
@MappedSuperClass
public class BaseEntity
{
@Id
@Column(name="record_id")
String id;
@Column(name="record_timestamp")
Date timestamp;
(.... getters, setters and so forth)
}
I then have derived another class
@Entity
@Table(name="report_company")
public class Company extends BaseEntity
{
@Column(name="business_date")
Date businessDate;
...getters/setters...
}
that works perfectly, the Company entity is retrieved nicely
But if I want to add one more layer, and change the Company (so level 2) class to be an "abstract" one (in the perstence sense)
@MappedSuperclass
public class Company extends BaseEntity
{
@Column(name="business_date")
Date businessDate;
...getters/setters...
}
and create another class (level 3)
@Entity
@Table(name="report_company")
public class ReportCompany extends BaseEntity
{
(class is empty, because all I need here is the table name in the annotation)
}
It does NOT work, nothing happens in my code, dont even get an error, but if I query for ReportCompany entities I always get an empty list
Where is the logic behind that, can @MappedSuperclass only be used once per hirarchy, and why does the reference not mention that??
Thanks a lot in advance, once again.
Cheers,
CC
ps.: Why I need this is simple, I have got a few fields common to every entity (id, status, ..), but then I also got three "Company" tables (actually functions) which look exactly the same, but should create three different objects - and I dont want to define them redundantly, it would seem really wrong)
- 03-24-2010, 12:05 PM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Read about the default inheritance strategy applied if you don't state one and what the discriminator value used will be. This should make you see why the search for ReportCompany entities doesn't return anything.
- 03-24-2010, 12:17 PM #3
Member
- Join Date
- Mar 2010
- Posts
- 11
- Rep Power
- 0
bling
>r035198x
You clearly are the quickest tech-forum replier ever! Thanks mate!
In this case it causes my embarrassment though, the issue waaaas *drumroll*, that I did not add the "level 3" class (ReportCompany) to my list of mapped classes (currently in a HibernateUtil class).
It might make sense to still leave this post in here, if people search at least they know this MappedSuperclass is defo possible!
Sorry, cheers though!
CC
- 03-24-2010, 12:22 PM #4
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
You still need to verify your inheritance strategy though and I suggest stating it explicitly in your root entity class (where the table annotation is).
- 03-24-2010, 12:26 PM #5
Member
- Join Date
- Mar 2010
- Posts
- 11
- Rep Power
- 0
Similar Threads
-
problem with Persistence.createEntityManagerFactory
By jordanthompson in forum Advanced JavaReplies: 7Last Post: 12-24-2009, 12:38 PM -
Name persistence is not bound in this Context
By tascoa in forum Java ServletReplies: 1Last Post: 12-15-2009, 10:01 PM -
javax.microedition.io/ javax.bluetooth
By ahtiven in forum New To JavaReplies: 3Last Post: 01-13-2009, 02:54 PM -
JDO - defining the persistence using metadata
By Java Tip in forum Java TipReplies: 0Last Post: 03-17-2008, 07:50 AM -
Container Managed Persistence
By Java Tip in forum Java TipReplies: 0Last Post: 12-27-2007, 10:16 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks