-->
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.  [ 7 posts ] 
Author Message
 Post subject: Inheriting Annotations without being Persistent
PostPosted: Sun Jan 14, 2007 8:14 pm 
Newbie

Joined: Sun Jan 14, 2007 8:01 pm
Posts: 5
I have a series of POJO classes that are mapped with Hibernate Annotations to my database.

For testing, I wanted to create default classes that extend my POJO classes, providing minimal data to meet the various check constraints on the database.

Is there any way to extend a Hibernate annotated class without mapping the subclass?

I could map them, define the inheritance as a table per subclass and insert dummy tables with the primary key, but I'd prefer not adding annotations to the original POJO for the test classes, nor adding to my schema when testing.

The only alternative I've come up with is to define static construction methods, but this wont let me add fields or override methods.


Top
 Profile  
 
 Post subject: Huh?
PostPosted: Mon Jan 15, 2007 6:07 pm 
Regular
Regular

Joined: Wed Aug 24, 2005 11:49 am
Posts: 63
Can you not just create a subclass, but without a @Entity annotation?

I think I don't understand the problem :-)

_________________
Edwin van der Elst
Finalist IT Group


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 15, 2007 6:14 pm 
Newbie

Joined: Sun Jan 14, 2007 8:01 pm
Posts: 5
If you don't add entity mappings, when saving the class the EntityManager will throw an exception since the test class is unmapped.

I wanted it to use the extended mappings; without having to map this class to a table.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 16, 2007 4:12 am 
Beginner
Beginner

Joined: Mon Sep 12, 2005 3:27 am
Posts: 48
See Hibernate documentation for @MappedSuperclass. That's what you want...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 16, 2007 3:38 pm 
Newbie

Joined: Sun Jan 14, 2007 8:01 pm
Posts: 5
Tried that as well. The "Test" class is not an entity, and so cannot be saved.

Generally your superclass is extended by actual entities, which can be saved.


Top
 Profile  
 
 Post subject: Inheriting Annotations without being Persistent
PostPosted: Tue Jan 16, 2007 6:02 pm 
Beginner
Beginner

Joined: Thu Jan 11, 2007 7:19 pm
Posts: 20
Location: Argentina, Buenos Aires
Really is don't clear why you need to extend the pojos to do that.

I does not sounds reasonable, I would create a factory with
all the necessary data for my entities something like this:


public class PojoTestFactory {

public static EntityOne getEntityOne()...
public static EntityTwo getEntityTwo()...
}

In each of this methods I will add the requires fields, and that's so.

Hope it helps
tonio


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 16, 2007 6:11 pm 
Newbie

Joined: Sun Jan 14, 2007 8:01 pm
Posts: 5
The factory approach works; but it does stop me from some polymorphic flexibility. I could add a boolean to add trace logging to see when data is changed. But since I can't add variables or extend any mapped class, that wont work.

I guess I'll settle for the factory. It works, I just can't add/override methods as I might have liked.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.