-->
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.  [ 4 posts ] 
Author Message
 Post subject: Extendending Hibernate Generated Classes
PostPosted: Sat Apr 03, 2004 2:15 am 
Beginner
Beginner

Joined: Fri Apr 02, 2004 3:34 am
Posts: 40
Hi,

I used hbm2java to generate a bunch of classes. Now, I am thinking about hand-coding a few classes that will derive from the auto-generated classes.

So, I can use Hibernate to persist my hand-coded classes? Are there any restrictions? I figure the new fields won't be persisted, but are there any other issues?

How about retrieval? I figure I cannot cast one of the auto-gen classes to my hand-coded class?!?

Thanks,
Acco


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 03, 2004 4:31 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
Quote:
I figure the new fields won't be persisted


are the new fields stored on db?
if yes just take a look at subclass, joined-subclass in the doc


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 03, 2004 3:25 pm 
Beginner
Beginner

Joined: Fri Apr 02, 2004 3:34 am
Posts: 40
Nope, the fields are transient. For example,

class Cat; // persistent per Hibernate Example.

class MyFatCat extends Cat;

Now, everytime I retrieve Cat (reads from the Cat table), I would the class returned to be MyFatCat and not Cat, is that possible?

For this particular example below,

Cat cat = (Cat) firstSession.load(Cat.class, catId);

it looks like I can use MyFatCat.class, but how about the more general cases? Like when the cats in are in a collection, will the type be Cat or can I specify it to be MyFatCat?

Note: I would like to achieve this without modifying the hbm mapping files at all.


Thanks,
Acco


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 05, 2004 7:33 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Will work, except
Code:
session.load(MySubclass.class, classId);

You should use
Code:
session.load(MyClass.class, classId);


Not sure of that but check.

_________________
Emmanuel


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